package com.gx.obe.management.webservice;

import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.gx.obe.WebserviceConstants;
import com.gx.obe.business.entity.BidPriceRound;
import com.gx.obe.business.entity.ScoreItem;
import com.gx.obe.business.entity.SignatureFile;
import com.gx.obe.business.entity.SupplierEvaluationFactor;
import com.gx.obe.business.entity.SupplierEvaluationStep;
import com.gx.obe.business.entity.Worker;
import com.gx.obe.business.enumeration.ExpertEnum;
import com.gx.obe.business.enumeration.SupplierEnum;
import com.gx.obe.business.http.HttpResponse;
import com.gx.obe.business.http.HttpUpload;
import com.gx.obe.business.http.HttpUrl;
import com.gx.obe.business.http.HttpUtils;
import com.gx.obe.business.http.UploadListener;
import com.gx.obe.business.vo.ExchangeRate;
import com.gx.obe.common.file.download.DownloadFileUtill;
import com.gx.obe.common.file.download.infer.DownloadFileListener;
import com.gx.obe.common.file.enumeration.FileConstants;
import com.gx.obe.common.file.service.SignatureFileService;
import com.gx.obe.common.file.utils.ZipUtils;
import com.gx.obe.components.core.enumeration.BidPriceEnum;
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.TenderProjectEnum;
import com.gx.obe.config.ConfigConstants;
import com.gx.obe.config.utils.PropertiesUtils;
import com.gx.obe.formula.BenchmarkPriceParam;
import com.gx.obe.formula.PriceParam;
import com.gx.obe.message.Messages;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.CollectionUtils;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.FileUtils;
import com.gx.obe.util.utils.ListSortUtils;
import com.gx.obe.util.utils.NumberFormatUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.util.utils.SerializeUtils;
import com.gx.obe.util.utils.StringUtils;
import com.gx.obe.util.utils.UuidUtils;
import com.gx.obe.util.utils.XmlUtils;
import com.gx.obe.web.entity.EvaluationFactorResult;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.SupplierEvaluationResult;
import com.gx.obe.web.entity.SupplierOpeningResult;
import com.gx.obe.web.entity.TransactionServer;
import com.gx.obe.web.entity.auth.AuthUser;
import com.gx.obe.web.entity.evaluation.EvaluationFactor;
import com.gx.obe.web.entity.evaluation.EvaluationGroup;
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.BidPriceHisResult;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.BidPriceHisResultService;
import com.gx.obe.web.service.BidPriceService;
import com.gx.obe.web.service.ProjectRuleService;
import com.gx.obe.web.service.ReBidPriceRoundService;
import com.gx.obe.web.service.SupplierEvaluationFactorService;
import com.gx.obe.web.service.SupplierEvaluationResultService;
import com.gx.obe.web.service.SupplierEvaluationStepService;
import com.gx.obe.web.service.SupplierOpeningResultService;
import com.gx.obe.web.service.SupplierService;
import com.gx.obe.web.service.TenderProjectService;
import com.gx.obe.web.service.WorkerService;
import com.gx.obe.web.service.evaluation.EvaluationFactorResultService;
import com.gx.obe.web.service.evaluation.EvaluationFactorService;
import com.gx.obe.web.service.evaluation.EvaluationGroupService;
import com.gx.obe.web.service.evaluation.EvaluationStepExpertService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;
import com.gx.obe.web.service.expert.ExpertEvaluationResultService;
import com.gx.obe.web.service.expert.ExpertService;
import com.gx.utils.ActionLogUtils;

/** 
  * @Description: 上传评标结果和评审产生的所有文档            		
  * @author guoyr
  */ 
	
public class UploadEvaluationResultAndFile implements IUploadEvaluateResult{
	private SignatureFileService signatureFileService = new SignatureFileService();
	private SupplierService supplierService = new SupplierService();
	private TenderProjectService tenderProjectService  = new TenderProjectService();
	private ProjectRuleService projectRuleService;
	private SupplierEvaluationStepService supplierEvaluationStepService = new SupplierEvaluationStepService();
	private EvaluationStepService evaluationStepService = new EvaluationStepService();
	private WorkerService workerService ;
	private ExpertService expertService = new ExpertService();
 	private ExpertEvaluationResultService expertEvaluationResultService;
	private EvaluationFactorService evaluationFactorService = new EvaluationFactorService();
	private SupplierEvaluationResultService supplierEvaluationResultService;
	private ReBidPriceRoundService reBidPriceRoundService;
	private Logger LOG = Logger.getLogger(UploadEvaluationResultAndFile.class);
	private UploadListener callBack;
	private TenderProjectEntity tenderProjectEntity;
	private TenderProjectRuleEntity tenderProjectRuleEntity;
	private TenderProjectEntity parentProject;
	private TransactionServer transactionServer;
	private List<Supplier> supplierList;
//	private String prjCode ;
//	private String packCode;
	private final String XML_ENCODING = "UTF-8";
	private EvaluationStepExpertService evaluationStepExpertService;
	private EvaluationFactorResultService evaluationFactorResultService = new EvaluationFactorResultService();
	private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private SupplierOpeningResultService supplierOpeningResultService = new SupplierOpeningResultService();
	private EvaluationGroupService evaluationGroupService;
	private SupplierEvaluationFactorService supplierEvaluationFactorService ;
	private List<EvaluationFactor> allEvaluationFactorList;
	private List<EvaluationStep> evaluationStepList;
	private List<Expert> allExpertList;
	private List<Worker> allWorkerList;
	private Map<String, SupplierEvaluationStep> supplierEvaluationStepMap = new HashMap<String, SupplierEvaluationStep>();
	private Map<String, ExpertEvaluationResult> expertEvaluationResultMap = new HashMap<String, ExpertEvaluationResult>();
	private Map<String, SupplierEvaluationResult> supplierEvaluationResultMap = new HashMap<String, SupplierEvaluationResult>();
	private Map<String, SupplierOpeningResult> supplierOpeningResultMap = new HashMap<String, SupplierOpeningResult>();
	private Map<String, List<Expert>> stepExpertListMap = new HashMap<String, List<Expert>>();
	private Map<String, List<EvaluationFactor>> stepEvaluationFactorListMap = new HashMap<String, List<EvaluationFactor>>();
	private Map<String, Expert> stepExpertMap = new HashMap<String, Expert>();
	private BidPriceHisResultService bidPriceHisResultService;
	private BidPriceService bidPriceService = new BidPriceService();
 
	/**
	 * @Description: 上传开标结果 
	 * @author guoyr
	 * @param tenderId
	 * @param tenderApplyRec
	 * @param messageReceiver
	 * @return
	 */
	public void uploadEvaluateResult(TenderProjectEntity tenderProjectEntity,  List<File> reportFileList, List<File> attachmentFileList, UploadListener callBack) {
		this.callBack = callBack;
		this.tenderProjectEntity = tenderProjectEntity;
		// 如果存在父级id，则说明是包件
		if(StringUtils.isNotEmpty(tenderProjectEntity.getParentId())){
			parentProject = (TenderProjectEntity) tenderProjectService.getById(tenderProjectEntity.getParentId());
//			prjCode = parentProject.getTenderNo();
//			packCode = tenderProjectEntity.getTenderNo();
			tenderProjectEntity.setParentProjectEntity(parentProject);
		}else {// 如果是不分包项目
//			prjCode = tenderProjectEntity.getTenderNo();
//			packCode = "";
		}
		transactionServer = HttpUtils.getTransactionServer(tenderProjectEntity.getTransactionServerId());
		boolean uploadSuccess = false;
		if (null != transactionServer) {
			boolean applySubmitEvalResult = applySubmitEvalResult(transactionServer);
			if(applySubmitEvalResult){
				callBackMsg("正在准备上传数据...");
				// 获得上传的结构化评标数据
				File zipFile = getZipFile(tenderProjectEntity, reportFileList, attachmentFileList, callBack);
				if(null != zipFile && zipFile.exists()){
					
					HttpUrl httpUrl = HttpUtils.getProjectHttpUrl(tenderProjectEntity, parentProject, transactionServer, PropertiesUtils.getWebserviceProperty(WebserviceConstants.UPLOAD_FILE_SERVLET, ""));
					httpUrl.setAttribute("fileType", "bidEvaluationResultFile");
					
					HttpUpload httpURLUpload=new HttpUpload(callBack);
					uploadSuccess = httpURLUpload.upload(httpUrl, zipFile);
					ActionLogUtils.addServerLog(tenderProjectEntity.getId(),"上传评标结果", httpUrl, uploadSuccess);
					if(uploadSuccess){
						tenderProjectEntity.setUploadEvaluationResultStatus(CommonEnum.COMPLETE);
						tenderProjectEntity.setComplateStatus(CommonEnum.COMPLETE);
						tenderProjectService.updateAssignProperty(tenderProjectEntity, new String[]{"uploadEvaluationResultStatus","complateStatus"});
					}
				}else {
					callBackMsg(false, "未找到要上传的文件！");
				}
			}
		} else {
			callBackMsg(false, "未找到要上传的服务器！");
		}
		if(null != callBack){
			callBack.finish(uploadSuccess);
		}
	}
	
	/**
	 * @Description: 生成上传评标结果的描述文件
	 * @author guoyr
	 * @param format
	 * @param name
	 * @param docId
	 * @param fileName
	 * @param type
	 * @return
	 */
	private Element addSectionElement(Element format, String name, String docId, String fileName, String type){
		Element selection = format.addElement("fileItem");
		selection.addElement("name").setText(XmlUtils.getXmlText(name));
		selection.addElement("fileId").setText(docId);
		selection.addElement("fileName").setText(XmlUtils.getXmlText(fileName));
		selection.addElement("type").setText(type);
		return format;
	}
	
	/**
	 * @Description: 生成专家评标结果ExpertEvalResult.xml
	 * @author guoyr
	 * @param path
	 * @return
	 */
	private boolean createEvalResultRecordXml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("expertEvalResultList");
			setExpertElementByExpert(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	
	/**
	 * @Description: 生成评审结果ExpertEvalResult.xml
	 * @author guoyr
	 * @param path
	 * @return
	 */
	private boolean createEvaluationResultXml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("evaluationResult");
			setEvaluationResult(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	
	/**
	 * @Description: 组装专家信息
	 * @param rootElement
	 * @return
	 */
	private Element setExpertElementByExpert(Element rootElement){
		
		if(null == allExpertList){
			allExpertList = expertService.getExpertList(tenderProjectEntity.getId(), ExpertEnum.ALL);
		}
		if(null != allExpertList){
			for(Expert expert : allExpertList){
				AuthUser user = expert.getUser();
				if(null == user){
					user = new AuthUser();
				}
				Element expertElement = rootElement.addElement("expert");
				expertElement.addElement("expertId").setText(XmlUtils.getXmlText(user.getId()));
				expertElement.addElement("expertName").setText(XmlUtils.getXmlText(user.getUserName()));
				expertElement.addElement("expertAccount").setText(XmlUtils.getXmlText(user.getUserAccount()));
				setSupplierElement(expertElement, expert);
			}
		}
		return rootElement;
	}
	
	/**
	 * @Description: 组装评审结果信息
	 * @param rootElement
	 * @return
	 */
	private Element setEvaluationResult(Element rootElement){
		String winBidType = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_winBidType);
		String childrenFirm = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_childrenFirm);
		String winnerName = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.WINNER_NAME);
		String winnerProperty = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.WINNER_PROPERTY);
		String winnerFoundTime = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.WINNER_FOUND_TIME);
		String winnerRegisterCapital = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.WINNER_REGISTER_CAPITAL);
		String winnerAchievement = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.WINNER_ACHIEVEMENT);
		String recommendReason = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_recommendReason);
		String vetoBidDetail = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_vetoBidDetail);
		String winnerReviewDetail = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_winnerReviewDetail);
		String bidPriceModifyMemo = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_bidPriceModifyMemo);
		String supplierProxyContent = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_supplierProxyContent);
		String other = tenderProjectEntity.getEvaluationParamByKey(TenderProjectEnum.EVALU_other);
		rootElement.addElement("winBidType").addText(XmlUtils.getXmlText(winBidType));
		rootElement.addElement("childrenFirm").addText(XmlUtils.getXmlText(childrenFirm));
		rootElement.addElement("winnerName").addText(XmlUtils.getXmlText(winnerName));
		rootElement.addElement("winnerProperty").addText(XmlUtils.getXmlText(winnerProperty));
		rootElement.addElement("winnerFoundTime").addText(XmlUtils.getXmlText(winnerFoundTime));
		rootElement.addElement("winnerRegisterCapital").addText(XmlUtils.getXmlText(winnerRegisterCapital));
		rootElement.addElement("winnerAchievement").addText(XmlUtils.getXmlText(winnerAchievement));
		rootElement.addElement("recommendReason").addText(XmlUtils.getXmlText(recommendReason));
		rootElement.addElement("vetoBidDetail").addText(XmlUtils.getXmlText(vetoBidDetail));
		rootElement.addElement("winnerReviewDetail").addText(XmlUtils.getXmlText(winnerReviewDetail));
		rootElement.addElement("bidPriceModifyMemo").addText(XmlUtils.getXmlText(bidPriceModifyMemo));
		rootElement.addElement("supplierProxyContent").addText(XmlUtils.getXmlText(supplierProxyContent));
		if(null != other) {
			rootElement.addElement("other").addText(XmlUtils.getXmlText(other));
		}else {
			rootElement.addElement("other").addText("");
		}
		
		rootElement.addElement("effectiveType").addText(XmlUtils.getXmlText(tenderProjectEntity.getEffectiveType()));
		rootElement.addElement("effectiveMemo").addText(XmlUtils.getXmlText(tenderProjectEntity.getEffectiveMemo()));
		return rootElement;
	}
	
	/**
	 * @Description: 组装投标人信息
	 * @param expertElement
	 * @param userId
	 */
	private void setSupplierElement(Element expertElement, Expert expert){
		for(Supplier supplier : supplierList){
			SupplierOpeningResult openBidResult = supplier.getSupplierOpeningResult();
			// 只有开标完成的投标人才会参与评标，所以只上传开标成功的投标人的评标结果
			if(null != openBidResult && null != openBidResult.getBidOpeningStatus() && openBidResult.getBidOpeningStatus().equals(SupplierEnum.OPENBID_SUCCESS)){
				Element supplierElement = expertElement.addElement("supplier");
				supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName()));
				supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
				supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				createExpertEvaluationResult(supplierElement, expert, supplier.getId());
			}
		}
	}
	/**
	 * @Description: 组装评审步骤评标结果信息
	 * @param supplierElement
	 * @param userId
	 * @param suppierId
	 */
	private void createExpertEvaluationResult(Element supplierElement, Expert expert, String suppierId){
		
		//已知条件：专家user_id,查找当前专家所拥有的评标步骤
		List<EvaluationStep> evaluationDetailStepList = getExpertEvaluationStepList(expert);
		if(null != evaluationDetailStepList){
			for(EvaluationStep evaluationStep : evaluationDetailStepList){
				// 专家在指定评标步骤下对供应商的评审结果
				ExpertEvaluationResult expertEvaluationResult = expertEvaluationResultMap.get(expert.getUserId() +"_"+ evaluationStep.getId() + "_"+ suppierId);
				
//				ExpertEvaluationResult expertEvaluationResult = expertEvaluationResultService.getSupplierExpertEvaluationResultList(tenderProjectEntity.getId(), expert.getUser().getId(), evaluationStep.getId(), suppierId);
				Element evalStepElement = supplierElement.addElement("evalStep");
				evalStepElement.addElement("stepId").setText(XmlUtils.getXmlText(evaluationStep.getId()));
				evalStepElement.addElement("stepName").setText(XmlUtils.getXmlText(evaluationStep.getStepName()));
				evalStepElement.addElement("stepType").setText(XmlUtils.getXmlText(evaluationStep.getStepType()));
				evalStepElement.addElement("evalBidType").setText(XmlUtils.getXmlText(evaluationStep.getEvalBidType()));
				evalStepElement.addElement("roleType").setText(XmlUtils.getXmlText(evaluationStep.getRoleType()));
				String evaluationScore = "";
				String evaluationFinalScore = "";
				String accessment = "";
				String sortNo = "";
				String opinion = "";
				if(null != expertEvaluationResult){
					evaluationScore = null != expertEvaluationResult.getEvaluationScore() ? expertEvaluationResult.getEvaluationScore().toString() : "";
					evaluationFinalScore = null != expertEvaluationResult.getEvaluationFinalScore() ? expertEvaluationResult.getEvaluationFinalScore().toString() : "";
					accessment = null != expertEvaluationResult.getAccessment() ? expertEvaluationResult.getAccessment() : "";
					sortNo = expertEvaluationResult.getSortNoIntValue() > 0 ? expertEvaluationResult.getSortNoIntValue() + "" : "";
					opinion = null != expertEvaluationResult.getSupplierOpinion() ? expertEvaluationResult.getSupplierOpinion() : "";
				}
				evalStepElement.addElement("evaluationScore").setText(evaluationScore);//评标得分
				evalStepElement.addElement("evaluationFinalScore").setText(evaluationFinalScore);//最终得分（含权重）
				evalStepElement.addElement("accessment").setText(accessment);
				evalStepElement.addElement("sortNo").setText(sortNo);
				evalStepElement.addElement("opinion").setText(XmlUtils.getXmlText(opinion));
			}
		}
	}
	
	
	
	
	/**
	 * 生成供应商评标结果SupplierEvalResult.xml
	 * @param path
	 * @return
	 */
	private boolean createSupplierEvalResultXml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("supplierEvalResultList");
			rootElement.addElement("evaluationMethod").setText(XmlUtils.getXmlText(tenderProjectRuleEntity.getEvalMethodType()));
			rootElement.addElement("evaluationMethodName").setText(XmlUtils.getXmlText(tenderProjectRuleEntity.getEvalMethodName()));
			rootElement.addElement("evaluationCurrencyCode").setText(tenderProjectRuleEntity.getEvalCurrencyCode());// 评标价币种
			rootElement.addElement("evaluationPriceUnit").setText(XmlUtils.getXmlText(tenderProjectRuleEntity.getEvalPriceUnit()));// 评标价单位
			rootElement.addElement("evaluationPriceUnitType").setText(XmlUtils.getXmlText(CommonEnum.getPriceUnitType(tenderProjectRuleEntity.getEvalPriceUnit())));// 评标价单位类型
			createSupplierEvaluationResult(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	
	/**
	 * 组装供应商列表
	 * @param rootElement
	 */
	private void createSupplierEvaluationResult(Element rootElement){
		if(null != supplierList){
			ExchangeRate exchangeRate = tenderProjectRuleEntity.getParamByKey("exchangeRate");
			if (null == exchangeRate) {
				exchangeRate = new ExchangeRate();
			}
			Map<String, BigDecimal> exchangeRateMap = exchangeRate.getExchangeRateMap();
			
			for(final Supplier supplier : supplierList){
				SupplierOpeningResult openBidResult = supplier.getSupplierOpeningResult();
				Element supplierElement = rootElement.addElement("supplier");
				supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName()));
				supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
				supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				String bidPrice = "";
				String finalBidPrice = "";
				String evaluationPrice = "";
				String currencyCode = BidPriceEnum.CUR_CODE;
				String priceUnit = tenderProjectRuleEntity.getPriceUnitUseDefault();
				String priceUnitType = CommonEnum.getPriceUnitType(tenderProjectRuleEntity.getPriceUnitUseDefault());
				String rate = "";
				if(null != openBidResult){
					bidPrice = NumberFormatUtils.trim(openBidResult.getBidPrice());
					finalBidPrice = NumberFormatUtils.trim(openBidResult.getBidPrice(openBidResult.getFinalBidPrice()));
					evaluationPrice = NumberFormatUtils.trim(openBidResult.getEvaluationPrice());
					if(StringUtils.hasLength(openBidResult.getCurrencyCode())) {
						currencyCode = openBidResult.getCurrencyCode();
					}
					priceUnit = openBidResult.getPriceUnitCN(tenderProjectRuleEntity.getPriceUnitUseDefault());
					priceUnitType =  CommonEnum.getPriceUnitType(openBidResult.getPriceUnitCN(tenderProjectRuleEntity.getPriceUnitUseDefault()));
					
					if(null != currencyCode && null != exchangeRateMap.get(currencyCode)){
						rate = exchangeRateMap.get(currencyCode).toString();
					}
				}
				supplierElement.addElement("bidPrice").setText(bidPrice);
				supplierElement.addElement("finalBidPrice").setText(finalBidPrice);
				// 投标价单位
				supplierElement.addElement("priceUnit").setText(XmlUtils.getXmlText(priceUnit));
				// 投标价单位类型
				supplierElement.addElement("priceUnitType").setText(XmlUtils.getXmlText(priceUnitType));
				// 投标价币种
				supplierElement.addElement("currencyCode").setText(XmlUtils.getXmlText(currencyCode));
				supplierElement.addElement("rate").setText(XmlUtils.getXmlText(rate));
				
				String evaluationScore = "";
				String evaluationFinalScore = "";
				String accessment = "";
				String priceScore = "";
				String priceFinalScore = "";
				String sortNo = "";
				String winSortNo = "";
				String opinion = "";
				String recommend = "";
				String winBidRecommend = "";
				String choiceType = "";
				String biddingRequest = "";
				String vetoType = "";
				SupplierEvaluationResult supplierEvaluationResult = supplierEvaluationResultMap.get(supplier.getId());
				if(null != supplierEvaluationResult){
					evaluationScore = null != supplierEvaluationResult.getEvaluationScore() ? supplierEvaluationResult.getEvaluationScore().toString() : "";
					evaluationFinalScore = null != supplierEvaluationResult.getEvaluationFinalScore() ? supplierEvaluationResult.getEvaluationFinalScore().toString() : "";
					accessment = null != supplierEvaluationResult.getAccessment() ? supplierEvaluationResult.getAccessment() : "";
					priceScore = null != supplierEvaluationResult.getPriceScore() ? supplierEvaluationResult.getPriceScore().toString() : "";
					priceFinalScore = null != supplierEvaluationResult.getPriceFinalScore() ? supplierEvaluationResult.getPriceFinalScore().toString() : "";
					sortNo = supplierEvaluationResult.getSortNo() > 0 ? supplierEvaluationResult.getSortNo() +"" : "";
					winSortNo = supplierEvaluationResult.getWinBidSortNo() > 0 ? supplierEvaluationResult.getWinBidSortNo() +"" : "";
					opinion = supplierEvaluationResult.getAccessment().equals("01") ? "" : supplierEvaluationResult.getEvaluationOpinion();
					//opinion = null != supplierEvaluationResult.getEvaluationOpinion() ? supplierEvaluationResult.getEvaluationOpinion() : "";
					recommend = null != supplierEvaluationResult.getRecommend() ? supplierEvaluationResult.getRecommend() : "";
					winBidRecommend = null != supplierEvaluationResult.getWinBidRecommend() ? supplierEvaluationResult.getWinBidRecommend() : "";
					choiceType = supplierEvaluationResult.getChoiceType();
					biddingRequest  = supplierEvaluationResult.getBiddingRequest();
					vetoType = supplierEvaluationResult.getVetoType();
				}
				supplierElement.addElement("evaluationPrice").setText(evaluationPrice);
				supplierElement.addElement("evaluationScore").setText(evaluationScore);
				supplierElement.addElement("evaluationFinalScore").setText(evaluationFinalScore);
				supplierElement.addElement("accessment").setText(accessment);
				supplierElement.addElement("priceScore").setText(priceScore);
				supplierElement.addElement("priceFinalScore").setText(priceFinalScore);
				supplierElement.addElement("sortNo").setText(sortNo);
				supplierElement.addElement("winSortNo").setText(winSortNo);
				supplierElement.addElement("opinion").setText(XmlUtils.getXmlText(opinion));
				if(biddingRequest!=null) {
					supplierElement.addElement("biddingRequest").setText(biddingRequest);
				}
				if(vetoType!=null) {
					supplierElement.addElement("vetoType").setText(vetoType);
				}
				if (winBidRecommend.isEmpty()) {
					supplierElement.addElement("recommend").setText(recommend);
				} else {
					supplierElement.addElement("recommend").setText(winBidRecommend);
				}
				supplierElement.addElement("choiceType").setText(XmlUtils.getXmlText(choiceType));
				createSupplierEvaluationStepResult(supplierElement,supplier);
			}
		}
	}
	
	/**
	 * 组装供应商评审步骤结果
	 * @param supplierElement
	 * @param supplier
	 */
	private void createSupplierEvaluationStepResult(Element supplierElement, Supplier supplier){
		if(null == evaluationStepList){
			evaluationStepList = evaluationStepService.getEvaluationStepList(tenderProjectEntity.getId());
		}
		//获取当前除了签到节点和推荐中标人两个节点以外的所有评审节点
		if(null != evaluationStepList){
			List<String> supplierStepList = new ArrayList<String>();
			supplierStepList.add(EvaluationStepEnum.COMPLIANCE);
			supplierStepList.add(EvaluationStepEnum.DETAIL);
			supplierStepList.add(EvaluationStepEnum.PRICE);
			for(EvaluationStep evaluationStep : evaluationStepList){
				if(supplierStepList.contains(evaluationStep.getStepType())){
					String evaluationScore = "";
					String evaluationFinalScore = "";
					String accessment = "";
					String sortNo = "";
					String opinion = "";
					Element stepElement = supplierElement.addElement("evalStep");
					stepElement.addElement("stepId").setText(evaluationStep.getId());
					stepElement.addElement("stepName").setText(XmlUtils.getXmlText(evaluationStep.getStepName()));
					stepElement.addElement("stepType").setText(XmlUtils.getXmlText(evaluationStep.getStepType()));
					stepElement.addElement("evalBidType").setText(XmlUtils.getXmlText(evaluationStep.getEvalBidType()));
					stepElement.addElement("roleType").setText(XmlUtils.getXmlText(evaluationStep.getRoleType()));
					//查询供应商当前评审步骤下评审结果
					SupplierEvaluationStep supplierEvaluationStep = supplierEvaluationStepMap.get(supplier.getId()+"_"+evaluationStep.getId());
					if(null != supplierEvaluationStep){
						evaluationScore = null != supplierEvaluationStep.getEvaluationScore() ? supplierEvaluationStep.getEvaluationScore().toString():"";
						evaluationFinalScore = null != supplierEvaluationStep.getEvaluationFinalScore()? supplierEvaluationStep.getEvaluationFinalScore().toString():"";
						accessment = null != supplierEvaluationStep.getAccessment() ? supplierEvaluationStep.getAccessment() : "";
						if(null == supplierEvaluationStep.getSortNo()) {
							sortNo = "0";
						}else {
							sortNo = supplierEvaluationStep.getSortNo().intValue() > 0 ? supplierEvaluationStep.getSortNo().intValue()+"" : "";
						}
						opinion = null != supplierEvaluationStep.getSupplierOpinion() ? supplierEvaluationStep.getSupplierOpinion() : "";
					}
					stepElement.addElement("accessment").setText(accessment);
					stepElement.addElement("evaluationScore").setText(evaluationScore);
					stepElement.addElement("evaluationFinalScore").setText(evaluationFinalScore);
					if(EvaluationStepEnum.PRICE.equals(evaluationStep.getStepType())){
						EvaluationFactor priceEvaluationFactor = null;
						// 获得评审指标集合
						List<EvaluationFactor> priceFactorList = stepEvaluationFactorListMap.get(evaluationStep.getId());
						if(null == priceFactorList){
							priceFactorList = getEvaluationStepFactorList(evaluationStep, true);
							stepEvaluationFactorListMap.put(evaluationStep.getId(), priceFactorList);
						}
						if(null != priceFactorList && priceFactorList.size() > 0){
							for(EvaluationFactor factor : priceFactorList){
								if(null != factor.getComputerParams()){
									priceEvaluationFactor = factor;
									break;
								}
							}
							if(null == priceEvaluationFactor){
								priceEvaluationFactor = priceFactorList.get(0);
							}
						}
						if(null != priceEvaluationFactor){
							BigDecimal basePrice = null;
							BigDecimal basePriceFloat = null;
							PriceParam priceParam = PriceParam.deserializePriceParam(priceEvaluationFactor.getComputerParams());;
							if(null != priceParam){
								priceParam.setPriceScorePoint(tenderProjectRuleEntity.getScoreRoundIntVal());
								BenchmarkPriceParam basePriceParam = priceParam.getBasePriceParam();
								if(null != basePriceParam && null != basePriceParam.getBasePriceFloat()){
									basePriceFloat = basePriceParam.getBasePriceFloat();
									if(basePriceParam.isDownFloat()){
										basePriceFloat = BigDecimalUtils.mul(basePriceParam.getBasePriceFloat(), new BigDecimal(-1));
									}
								}
							}
							
							Expert commonExpert = stepExpertMap.get(evaluationStep.getId());
							if(null == commonExpert){
								commonExpert = expertService.getEvaluationStepExpert(tenderProjectEntity.getId(), evaluationStep);
								stepExpertMap.put(evaluationStep.getId(), commonExpert);
							}
							List<EvaluationFactorResult> evaluateFactorResultList = evaluationFactorResultService.getExpertEvaluationFactorResult(tenderProjectEntity.getId(), evaluationStep.getId(), commonExpert.getUserId(), supplier.getId());
							if(null != evaluateFactorResultList && evaluateFactorResultList.size() > 0){
								// 基准价
								basePrice = evaluateFactorResultList.get(0).getBasePrice();
							}
							// 浮动系数
							stepElement.addElement("basePriceFloat").setText(XmlUtils.getXmlText(basePriceFloat));
							stepElement.addElement("basePrice").setText(XmlUtils.getXmlText(NumberFormatUtils.trim(basePrice)));
						}
					
					}
					stepElement.addElement("sortNo").setText(sortNo);
					stepElement.addElement("opinion").setText(XmlUtils.getXmlText(opinion));
					if(!EvaluationStepEnum.OPERATOR.equals(evaluationStep.getRoleType())){
						setExpertEvaluationResultToSupplier(stepElement, supplier.getId(), evaluationStep);
					}
				}
			}
		}
	}
	
	/**
	 * @Description: 获得指定评标步骤的指标
	 * @author guoyr
	 * @param stepId
	 * @return
	 */
	private List<EvaluationFactor> getEvaluationStepFactorList(EvaluationStep evaluationStep, boolean removeTopOnly){
		List<EvaluationFactor> factorList = evaluationFactorService.getEvaluationStepFactorList(tenderProjectEntity.getId(), evaluationStep, removeTopOnly);
		// 未获得有效的指标，则创建1个临时指标。
		if(null == factorList || factorList.size() < 1){
			EvaluationFactor evalFactor = new EvaluationFactor();
			evalFactor.setId(UuidUtils.getUUID());
			evalFactor.setFactorName("指标");
			if(evaluationStep.getStepType().equals(EvaluationStepEnum.PRICE)){
				evalFactor.setBidPriceCode(BidPrice.BID_PRICE_TOTAL_CODE);
			}
			factorList.add(evalFactor);
		}
		return factorList;
	}
	/**
	 * 组装供应商评审步骤各评审专家评审结果
	 * @param stepElement
	 * @param supplierId
	 * @param stepId
	 */
	private void setExpertEvaluationResultToSupplier(Element stepElement, String supplierId, EvaluationStep evaluationStep){
		
		//查询当前步骤下面的评审专家
		List<Expert> expertList = stepExpertListMap.get(evaluationStep.getId());
		if(null == expertList){
			expertList = expertService.getEvaluationStepExpertList(tenderProjectEntity.getId(), evaluationStep);
			stepExpertListMap.put(evaluationStep.getId(), expertList);
		}
//		List<ExpertEvaluationResult> expertEvaluationResultList = expertEvaluationResultService.getSupplierExpertEvaluationResultList(tenderProjectEntity.getId(),  evaluationStep.getId(), supplierId);
		
		if(null != expertList){
			for(final Expert expert : expertList){
				String expertName = "";
				String expertAccount = "";
				String evaluationScore = "";
				String evaluationFinalScore = "";
				String accessment = "";
				String sortNo = "";
				String opinion = "";
				if(null != expert.getUser() && null != expert.getUser().getUserName()){
					expertName = expert.getUser().getUserName();
				}else if(null != expert.getUserName()){
					expertName = expert.getUserName();
				}else if(null != expert.getUser() && null != expert.getUser().getUserAccount()) {
					expertName = expert.getUser().getUserAccount();
				}
				if(null != expert.getUser() && null != expert.getUser().getUserAccount()) {
					expertAccount = expert.getUser().getUserAccount();
				}
				ExpertEvaluationResult expertEvaluationResult = expertEvaluationResultMap.get(expert.getUserId() +"_"+ evaluationStep.getId() + "_"+ supplierId);
				
//				ExpertEvaluationResult expertEvaluationResult = expertEvaluationResultService.getSupplierExpertEvaluationResultList(tenderProjectEntity.getId(), expert.getUserId(), evaluationStep.getId(), supplierId);
//				ExpertEvaluationResult expertEvaluationResult = CollectionUtils.get(expertEvaluationResultList, new CollectionUtils.Filter<ExpertEvaluationResult>() {
//					public boolean select(ExpertEvaluationResult t) {
//						return t.getUserId().equals(expert.getUserId());
//					}
//				});
				if(null != expertEvaluationResult){
					evaluationScore = null != expertEvaluationResult.getEvaluationScore() ? expertEvaluationResult.getEvaluationScore().toString() : "";
					evaluationFinalScore = null != expertEvaluationResult.getEvaluationFinalScore() ? expertEvaluationResult.getEvaluationFinalScore().toString() : "";
					accessment = null != expertEvaluationResult.getAccessment() ? expertEvaluationResult.getAccessment() : "";
					sortNo = expertEvaluationResult.getSortNoIntValue() > 0 ? expertEvaluationResult.getSortNoIntValue()+"" : "";
					opinion = null != expertEvaluationResult.getSupplierOpinion() ? expertEvaluationResult.getSupplierOpinion() : "";
				}
				Element expertElement = stepElement.addElement("expert");
				expertElement.addElement("expertName").setText(XmlUtils.getXmlText(expertName));
				expertElement.addElement("expertAccount").setText(expertAccount);
				expertElement.addElement("evaluationScore").setText(evaluationScore);
				expertElement.addElement("evaluationFinalScore").setText(evaluationFinalScore);
				expertElement.addElement("accessment").setText(accessment);
				expertElement.addElement("sortNo").setText(sortNo);
				expertElement.addElement("opinion").setText(XmlUtils.getXmlText(opinion));
			}
		}
	}
	
	/**
	 * 生成详细评审EvaluationScore.xml
	 * @param path
	 * @return
	 */
	private boolean createEvaluationScoreXml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("scoreResult");
			rootElement.addElement("name").setText(XmlUtils.getXmlText(tenderProjectEntity.getTenderName()));
			rootElement.addElement("code").setText(XmlUtils.getXmlText(tenderProjectEntity.getTenderNo()));
			setExpertToEvaluationScore(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	
	/**
	 * @Description: 添加详细评分中专家信息
	 * @author guoyr
	 * @param rootElement 
	 */
	private void setExpertToEvaluationScore(Element rootElement){
		if(null == allExpertList){
			allExpertList = expertService.getExpertList(tenderProjectEntity.getId(), ExpertEnum.ALL);//(tenderProjectEntity.getId(), evaluationStep);
		}
		if(null != allExpertList){
			for(Expert expert : allExpertList){
				Element expertElement = rootElement.addElement("expert");
				AuthUser user = expert.getUser();
				if(null == user){
					user = new AuthUser();
				}
				expertElement.addElement("account").setText(XmlUtils.getXmlText(user.getUserAccount()));
				expertElement.addElement("expertId").setText(XmlUtils.getXmlText(user.getId()));
				expertElement.addElement("name").setText(XmlUtils.getXmlText(user.getUserName())) ;
				expertElement.addElement("idCard").setText(XmlUtils.getXmlText(user.getUserIdcard()));
				expertElement.addElement("isLeader").setText(XmlUtils.getXmlText(expert.getIsLeader()));
				expertElement.addElement("company").setText(XmlUtils.getXmlText(user.getCompany()));
				setStepToEvaluationScore(expertElement,expert);
			}
		}
	}
	
	
	/**
	 * @Description: 添加详细评分中评标步骤信息
	 * @author guoyr
	 * @param expertElement 
	 */
	private void setStepToEvaluationScore(Element expertElement, Expert expert){
		//已知条件：专家user_id,查找当前专家所拥有的评标步骤
		List<EvaluationStep> evaluationDetailStepList = getExpertEvaluationStepList(expert);
		if(null != evaluationDetailStepList){
			for(EvaluationStep evaluationStep : evaluationDetailStepList){
				if(EvaluationStepEnum.DETAIL.equals(evaluationStep.getStepType())){
					Element evaluationStepElement = expertElement.addElement("EvaluationStep");// 这里应该为小写，但因为已和平台设计通过，不能随便修改
					evaluationStepElement.addElement("stepName").setText(XmlUtils.getXmlText(evaluationStep.getStepName()));
					evaluationStepElement.addElement("stepType").setText(XmlUtils.getXmlText(evaluationStep.getStepType()));
					evaluationStepElement.addElement("evalBidType").setText(XmlUtils.getXmlText(evaluationStep.getEvalBidType()));
					List<EvaluationFactor> listEvaluationFactor = stepEvaluationFactorListMap.get(evaluationStep.getId());
					if(null == listEvaluationFactor){
						listEvaluationFactor = evaluationFactorService.getEvaluationStepFactorList(tenderProjectEntity.getId(), evaluationStep, true);
						stepEvaluationFactorListMap.put(evaluationStep.getId(), listEvaluationFactor);
					}
					setSupplierToEvaluationScore(evaluationStepElement, evaluationStep, listEvaluationFactor);
				}
			}
		}
	}
	
	/**
	 * @Description: 添加详细评分中供应商信息
	 * @author guoyr
	 * @param evaluationStepElement
	 * @param evaluationStep 
	 */
	private void setSupplierToEvaluationScore(Element evaluationStepElement, EvaluationStep evaluationStep, List<EvaluationFactor> listEvaluationFactor){
		if(null != supplierList){
			for(Supplier supplier : supplierList){
				Element supplierElement = evaluationStepElement.addElement("supplier");
				supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName()));
				supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
				supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				setStepDetailedEavluactionScore(supplierElement, evaluationStep, listEvaluationFactor);
			}
		}
	}
	
	/**
	 * @Description: 添加详细评分中评审专家对供应商详细评审信息
	 * @author guoyr
	 * @param supplierElement
	 * @param evaluationStep 
	 */
	private void setStepDetailedEavluactionScore(Element supplierElement, EvaluationStep evaluationStep, List<EvaluationFactor> listEvaluationFactor){
		if(null != listEvaluationFactor){
			
			for(EvaluationFactor evaluationFactor : listEvaluationFactor){
				Element evaluationFactorEemelent = supplierElement.addElement("factor");
				evaluationFactorEemelent.addElement("id").setText(evaluationFactor.getId());
				evaluationFactorEemelent.addElement("name").setText(XmlUtils.getXmlText(evaluationFactor.getFactorName()));
				evaluationFactorEemelent.addElement("parentId").setText(null == evaluationFactor.getParentId() ? "" : evaluationFactor.getParentId());
				evaluationFactorEemelent.addElement("code").setText(null == evaluationFactor.getFactorCode() ? "" : evaluationFactor.getFactorCode());
				evaluationFactorEemelent.addElement("auditType").setText(evaluationFactor.getAuditType());
				evaluationFactorEemelent.addElement("score").setText(evaluationFactor.getFactorScore()+"");
			}
		}
	}
	
	/**
	 * @Description: 申请上传评标结果 
	 * @author guoyr
	 * @param properties
	 * @param tenderProjectEntity
	 * @return
	 */
	private boolean applySubmitEvalResult(TransactionServer transactionServer){
		HttpUrl httpUrl = HttpUtils.getProjectHttpUrl(tenderProjectEntity, parentProject, transactionServer, PropertiesUtils.getWebserviceProperty(WebserviceConstants.APPLYSUBMIT_EVALRESULT_METHOD, ""));
		/**				
			"tenderNo":项目编号
			"packCode":包件编号     
			"fileType":文件类型 招标文件biding 解密后投标文件 decryptBidFile 开标结果文件bidOpeningResultFile 评标结果文件bidEvaluationResultFile
			"userName":用户名
     		"password": 密码
			stageType：阶段类型[00表示资格预审阶段 01表示招标文件阶段 默认01]
			"stageId":阶段id
		 * */
		httpUrl.setAttribute("fileType", "bidEvaluationResultFile");
		httpUrl.setName("上传评标结果");
		
		HttpResponse httpResponse = HttpUtils.doPost(httpUrl);
		if(httpResponse.getStatus()){
			callBackMsg(true, "请求通过，允许上传。");
			return true;
		}else {
			callBackMsg(false, "请求拒绝，不允许上传！");
			callBackMsg(false, "服务器消息："+ ObjectUtils.getObjString(httpResponse.getMsg()));
			return false;
		}
	}

	/**
	 * @Description: 生成压缩文件
	 * @param tenderId
	 * @return
	 */
	public File getZipFile(TenderProjectEntity tenderProjectEntity, List<File> reportFileList, List<File> uploadFileList, UploadListener zipCallBack){
		if(null == supplierEvaluationResultService){
			supplierEvaluationResultService = new SupplierEvaluationResultService();
		}
		this.tenderProjectEntity = tenderProjectEntity;
		if(null != zipCallBack){
			this.callBack = zipCallBack;
		}
		if(null == supplierEvaluationStepService){
			supplierEvaluationStepService = new SupplierEvaluationStepService();
		}
		if(null == projectRuleService){
			projectRuleService = new ProjectRuleService();
		}
		tenderProjectRuleEntity = projectRuleService.getProjectRule(tenderProjectEntity.getId());
		if(null == tenderProjectRuleEntity)tenderProjectRuleEntity = new TenderProjectRuleEntity();
//		supplierList = supplierService.getSupplierOpenbidAndEvaluateResultList(tenderProjectEntity.getId());
		supplierList = supplierService.getOpenBidSuccessSupplier(tenderProjectEntity.getId());
		if(null == supplierList){
			supplierList = new ArrayList<Supplier>();
		}
		List<SupplierEvaluationStep> supplierEvaluationStepList = supplierEvaluationStepService.getSupplierEvaluationStepByTenderId(tenderProjectEntity.getId());
		if(null != supplierEvaluationStepList){
			for(SupplierEvaluationStep supplierEvaluationStep : supplierEvaluationStepList){
				supplierEvaluationStepMap.put(supplierEvaluationStep.getSupplierId()+"_"+supplierEvaluationStep.getStepId(), supplierEvaluationStep);
			}
		}
		if(null == 	expertEvaluationResultService ){
			expertEvaluationResultService = new ExpertEvaluationResultService();
		}
 
		List<ExpertEvaluationResult> expertEvaluationResultList = expertEvaluationResultService.getAllExpertEvaluationResultList( tenderProjectEntity.getId());
		if(null != expertEvaluationResultList){
			for(ExpertEvaluationResult expertEvaluationResult : expertEvaluationResultList){
				// 专家在指定评标步骤下对供应商的评审结果
				expertEvaluationResultMap.put(expertEvaluationResult.getUserId() +"_"+ expertEvaluationResult.getStepId() + "_" + expertEvaluationResult.getSupplierId(), expertEvaluationResult);
			}
		}
		
		//供应商评审结果
		List<SupplierEvaluationResult> supplierEvaluationResultList = supplierEvaluationResultService.getSupplierEvaluationResultListByTenderId(tenderProjectEntity.getId());
		if(null != supplierEvaluationResultList){
			for(SupplierEvaluationResult supplierEvaluationResult : supplierEvaluationResultList){
				supplierEvaluationResultMap.put(supplierEvaluationResult.getSupplierId(), supplierEvaluationResult);
			}
		}
 
		List<SupplierOpeningResult> supplierOpeningResultList = supplierOpeningResultService.getSupplierOpeningResultListByTenderId(tenderProjectEntity.getId());
		if(null != supplierOpeningResultList){
			for(SupplierOpeningResult supplierOpeningResult : supplierOpeningResultList){
				supplierOpeningResultMap.put(supplierOpeningResult.getSupplierId(), supplierOpeningResult);
			}
		}
		
		List<String> zipFileList = new ArrayList<String>(); 
		File zipFolder = new File(FileConstants.TEMP_PATH+tenderProjectEntity.getId());
		String autoCreateFilePath =zipFolder.getAbsolutePath()+File.separator+ "auto" + File.separator;
		String uploadFilePath =zipFolder.getAbsolutePath()+File.separator + "upload" + File.separator;
		boolean reCreateFile = true;
		if(reCreateFile){
			ExecutorService executorService = null;
			if(reportFileList!=null && reportFileList.size()>0){
				List<SignatureFile> signatureFileList = signatureFileService.getSignatureFileList(tenderProjectEntity.getId(),FileConstants.REPORT_FILE_FOLDER);
				if (CollectionUtils.isNotNull(signatureFileList)) {
					executorService = Executors.newFixedThreadPool(signatureFileList.size() > 5 ? 5 : signatureFileList.size());
					for (SignatureFile signatureFile : signatureFileList) {
						String fileURL = "/".concat(tenderProjectEntity.getId()).concat("/").concat(FileConstants.REPORT_FILE_FOLDER).concat("/").concat(signatureFile.getFileName());
						new DownloadFileUtill(fileURL, signatureFile.getFileName(), null, FileConstants.getReportFilePath(tenderProjectEntity.getId()), new DownloadFileListener() {
							public void writeSize(long size) {}
							
							public void speed(String speed) {}
							
							public void remainingTime(String remainingTime) {}
							
							public void progress(int percent) {}
							
							public void complate(boolean flag) {}
							
							public void checkMD5(boolean flag) {}
						}).startDownloadFile(executorService);;
					}
					executorService.shutdown();
				}
			}
			if(new File(autoCreateFilePath).exists()){
				FileUtils.delAllFile(autoCreateFilePath);
			}else {
				new File(autoCreateFilePath).mkdirs();
			}
			// 此处是为了单独调用时需要重新加载一边父级
			if(StringUtils.isNotEmpty(tenderProjectEntity.getParentId()) && null == tenderProjectEntity.getParentProjectEntity()){
				TenderProjectEntity parent = tenderProjectService.getById(tenderProjectEntity.getParentId());
				tenderProjectEntity.setParentProjectEntity(parent);
			}
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("bidEvaluationResultFileItemList");
//			rootElement.addAttribute("name", "投标文件格式");
//			rootElement.addElement("prjName").setText(null != tenderProjectEntity.getParent()?tenderProjectEntity.getParent().getTenderName():tenderProjectEntity.getTenderName());
//			rootElement.addElement("prjCode").setText(null != tenderProjectEntity.getParent()?tenderProjectEntity.getParent().getTenderNo():tenderProjectEntity.getTenderNo());
			
//			Element format;
			// 当前项目没有分包
//			if(null == tenderProjectEntity.getParent()){
//				rootElement= rootElement.addElement("format");
//			}else {
//				Element packsElement = rootElement.addElement("packs");
//				Element packElement = packsElement.addElement("pack");
//				packElement.addElement("packName").setText(tenderProjectEntity.getTenderName());
//				packElement.addElement("packCode").setText(tenderProjectEntity.getTenderNo());
//				rootElement= packElement.addElement("format");
//			}
			rootElement.addAttribute("name", "评审指标文件格式");
			
			File uploadEvalResultRecordFile = new File(autoCreateFilePath+"ExpertEvalResult.xml");
			callBackMsg("正在生成评标结果...");
			createEvalResultRecordXml(uploadEvalResultRecordFile.getAbsolutePath());
			if(uploadEvalResultRecordFile.exists()){
				addSectionElement(rootElement, "评标结果", "ExpertEvalResult", uploadEvalResultRecordFile.getName(), "sytemReport");
				zipFileList.add(uploadEvalResultRecordFile.getAbsolutePath());
			}
			
			File uploadEvaluationResultFile = new File(autoCreateFilePath+"EvaluationResult.xml");
			callBackMsg("正在生成评审结果...");
			createEvaluationResultXml(uploadEvaluationResultFile.getAbsolutePath());
			if(uploadEvaluationResultFile.exists()){
				addSectionElement(rootElement, "评审结果", "EvaluationResult", uploadEvaluationResultFile.getName(), "sytemReport");
				zipFileList.add(uploadEvaluationResultFile.getAbsolutePath());
			}
			
			File upLoadSupplierValuactionFile = new File(autoCreateFilePath+"SupplierEvalResult.xml");
			callBackMsg("正在生成供应商评审结果...");
			createSupplierEvalResultXml(upLoadSupplierValuactionFile.getAbsolutePath());
			if(upLoadSupplierValuactionFile.exists()){
				addSectionElement(rootElement, "供应商评审结果", "SupplierEvalResult", upLoadSupplierValuactionFile.getName(), "sytemReport");
				zipFileList.add(upLoadSupplierValuactionFile.getAbsolutePath());
			}
			
			File upLoadcreateClearBidContentXml = new File(autoCreateFilePath+"ClearBidContent.xml");
//			callBackMsg("正在生成清标内容...");
			createClearBidContentXml(upLoadcreateClearBidContentXml.getAbsolutePath());
			if(upLoadcreateClearBidContentXml.exists()){
				addSectionElement(rootElement, "清标内容", "ClearBidContent", upLoadcreateClearBidContentXml.getName(), "sytemReport");
				zipFileList.add(upLoadcreateClearBidContentXml.getAbsolutePath());
			}
			
			File upLoadcreateEvaluationScoreXml = new File(autoCreateFilePath+"EvaluationScores.xml");
			callBackMsg("正在生成供应商详细评审结果...");
			createEvaluationScoreXml(upLoadcreateEvaluationScoreXml.getAbsolutePath());
			if(upLoadcreateEvaluationScoreXml.exists()){
				addSectionElement(rootElement, "供应商详细评审结果", "EvaluationScore", upLoadcreateEvaluationScoreXml.getName(), "sytemReport");
				zipFileList.add(upLoadcreateEvaluationScoreXml.getAbsolutePath());
			}
			
			
			File upLoadExpertXml = new File(autoCreateFilePath+"Expert.xml");
			callBackMsg("正在生成专家信息...");
			createExpertXml(upLoadExpertXml.getAbsolutePath());
			if(upLoadExpertXml.exists()){
				addSectionElement(rootElement, Messages.Title_expertInfo, "Expert", upLoadExpertXml.getName(), "sytemReport");
				zipFileList.add(upLoadExpertXml.getAbsolutePath());
			}
			File upLoadEvaluationStepXml = new File(autoCreateFilePath+"EvaluationStep.xml");
			callBackMsg("正在生成评标步骤信息...");
			createupLoadEvaluationStepXml(upLoadEvaluationStepXml.getAbsolutePath());
			if(upLoadEvaluationStepXml.exists()){
				addSectionElement(rootElement, "评标步骤信息", "EvaluationStep", upLoadEvaluationStepXml.getName(), "sytemReport");
				zipFileList.add(upLoadEvaluationStepXml.getAbsolutePath());
			}
			
			File upLoadMultiRoundPriceXml = new File(autoCreateFilePath+"MultiRoundsBidPrice.xml");
			callBackMsg("正在生成多轮报价结果...");
			createMultiRoundsBidPrice(upLoadMultiRoundPriceXml.getAbsolutePath());
			if(upLoadMultiRoundPriceXml.exists()){
				addSectionElement(rootElement, "多轮报价信息", "MultiRoundsBidPrice", upLoadMultiRoundPriceXml.getName(), "sytemReport");
				zipFileList.add(upLoadMultiRoundPriceXml.getAbsolutePath());
			}
			
			File associationOpinionXml = new File(autoCreateFilePath+"AssociationOpinionXml.xml");
			callBackMsg("正在生成关联关系查询结果...");
			createAssociationOpinion(associationOpinionXml.getAbsolutePath());
			if(associationOpinionXml.exists()){
				addSectionElement(rootElement, "关联关系", "AssociationOpinion", associationOpinionXml.getName(), "sytemReport");
				zipFileList.add(associationOpinionXml.getAbsolutePath());
			}
			
			
			File upLoadWasteBidReasonXml = new File(autoCreateFilePath+"WasteBidReason.xml");
			callBackMsg("正在生成废标意见表...");
			createWasteBidReason(upLoadWasteBidReasonXml.getAbsolutePath());
			if(upLoadWasteBidReasonXml.exists()){
				addSectionElement(rootElement, "废标意见", "WasteBidReason", upLoadWasteBidReasonXml.getName(), "sytemReport");
				zipFileList.add(upLoadWasteBidReasonXml.getAbsolutePath());
			}
			
			File upLoadFactorsEvalResultxml = new File(autoCreateFilePath+"FactorsEvalResult.xml");
			callBackMsg("正在生成评标步骤详细评审信息...");
			createFactorsEvalResultxml(upLoadFactorsEvalResultxml.getAbsolutePath());
			if(upLoadFactorsEvalResultxml.exists()){
				addSectionElement(rootElement, "评标步骤详细评审信息", "FactorsEvalResult", upLoadFactorsEvalResultxml.getName(), "sytemReport");
				zipFileList.add(upLoadFactorsEvalResultxml.getAbsolutePath());
			}
			
			File upLoadEvaluationFactorsxml = new File(autoCreateFilePath+"EvaluationFactors.xml");
			callBackMsg("正在生成评审指标信息...");
			createEvaluationFactorsxml(upLoadEvaluationFactorsxml.getAbsolutePath());
			if(upLoadEvaluationFactorsxml.exists()){
				addSectionElement(rootElement, "评审指标信息", "EvaluationFactors", upLoadEvaluationFactorsxml.getName(), "sytemReport");
				zipFileList.add(upLoadEvaluationFactorsxml.getAbsolutePath());
			}
			if(reportFileList!=null && reportFileList.size()>0){
				if (executorService != null) {
					try {
						executorService.awaitTermination(1, TimeUnit.DAYS);
					} catch (InterruptedException e) {
						LOG.error("", e);
					}
				}
				for (File reportFile : reportFileList) {
					int suffixIndex = reportFile.getName().lastIndexOf(".");
					if(suffixIndex > 0){
						String fileType = reportFile.getName().substring(suffixIndex+1);
						String reportNameUUID = UuidUtils.getUUID();
						String reportName = reportFile.getName().substring(0, suffixIndex);//导出报表的名称
//					if ("xlsx".equals(fileType) || "pdf".equals(fileType) || "doc".equals(fileType) || "docx".equals(fileType)){}
						
						File uuidReportFile = new File(autoCreateFilePath+reportNameUUID+"." + fileType);
						callBackMsg("正在生成"+reportFile.getName()+"...");
						if(FileUtils.copy(reportFile.getAbsolutePath(), uuidReportFile.getAbsolutePath())){
							callBackMsg(true, reportFile.getName()+"生成成功！");
						}else{
							callBackMsg(false, reportFile.getName()+"生成失败！");
						}
						if(uuidReportFile.exists()){
							String reportType = "evalReport";
							if(reportName.contains("评标报告") || reportName.contains("评审报告")){
								reportType = "bidEvaluationReport";
							}
							addSectionElement(rootElement, reportName+"", reportNameUUID, uuidReportFile.getName(),  reportType);
							zipFileList.add(uuidReportFile.getAbsolutePath());
						}
					}
				
				}
			}
			
			File uploadUUidNameFile = new File(uploadFilePath+ "uuidName");
			if(uploadUUidNameFile.exists()){
				FileUtils.delAllFile(uploadUUidNameFile.getAbsolutePath());
			}else {
				uploadUUidNameFile.mkdirs();
			}
			if(null != uploadFileList && uploadFileList.size() > 0){
				for(File file : uploadFileList){
					String fileName = file.getName();
					String fileExt = "";
					String uuid = UuidUtils.getUUID();
					if(file.getName().indexOf(".") > 0){
						fileName = file.getName().substring(0, file.getName().indexOf("."));
						fileExt = file.getName().substring(file.getName().indexOf(".")+1);
					}
					String newFileName =  uploadUUidNameFile.getAbsolutePath() + File.separator + uuid +"." + fileExt;
					FileUtils.copy(file.getAbsolutePath(), newFileName);
					addSectionElement(rootElement, fileName, uuid, file.getName(), "evalReport");
					zipFileList.add(newFileName);
				}
			}
			
			
			
			callBackMsg("正在生成评标结果描述文件...");
			XmlUtils.createXmlFile(document, autoCreateFilePath+"BidEvaluationResultFileIndex.xml", XML_ENCODING);
			zipFileList.add(autoCreateFilePath+"BidEvaluationResultFileIndex.xml");
		}
		
		
		callBackMsg("开始压缩评标结果...");
		boolean zipSuccess = false;
		File zipFile = new File(new File(zipFolder.getAbsolutePath())+File.separator+"evalResult.zip");
		if(null != zipFile && zipFile.exists()){
			zipFile.delete();
		}
		try {
			ZipUtils.zip((String[])zipFileList.toArray(new String[zipFileList.size()]), zipFile.getAbsolutePath(), "评标结果", false, null);
			zipSuccess = true;
		} catch (Exception e) {
			callBackMsg(false, "压缩评标结果失败！");
			LOG.error("", e);
		}
		
		if(zipSuccess){
			callBackMsg("压缩结束，总大小:"+FileUtils.getFileSize(FileUtils.getFileSize(zipFile)));
		}
		if(zipSuccess){
			return zipFile;
		}else{
			return null;
		}
	}
	
	/**
	 * @Description: 生成清标内容ClearBidContent.xml
	 * @author chenxw
	 * @param absolutePath 
	 */
	private void createClearBidContentXml(String path) {
		Document document = DocumentHelper.createDocument();
		Element rootElement = document.addElement("clearBidContent");
		rootElement.addElement("name").setText(XmlUtils.getXmlText(tenderProjectEntity.getTenderName()));
		rootElement.addElement("code").setText(XmlUtils.getXmlText(tenderProjectEntity.getTenderNo()));
		rootElement.addElement("evaluationCurrencyCode").setText(tenderProjectRuleEntity.getEvalCurrencyCode());// 评标价币种
		rootElement.addElement("evaluationPriceUnit").setText(XmlUtils.getXmlText(tenderProjectRuleEntity.getEvalPriceUnit()));// 评标价单位
		rootElement.addElement("evaluationPriceUnitType").setText(XmlUtils.getXmlText(CommonEnum.getPriceUnitType(tenderProjectRuleEntity.getEvalPriceUnit())));// 评标价单位类型
		
		setSupplierToClearBidContent(rootElement.addElement("supplierList"));
		XmlUtils.createXmlFile(document, path, XML_ENCODING);
	}

	/**
	 * @Description: 添加供应商节点
	 * @author chenxw
	 * @param supplierListElement 
	 */
	private void setSupplierToClearBidContent(Element supplierListElement) {
		if(null == evaluationGroupService){
			evaluationGroupService = new EvaluationGroupService();
		}
		if (CollectionUtils.isNull(supplierList)) {
			return;
		}
		Map<String, Map<String, EvaluationGroup>> groupTypeMapSupplierMap = evaluationGroupService.getGroupTypeMapSupplierMap(tenderProjectEntity.getId());
		Map<String, Map<String, SupplierEvaluationFactor>> opinionFactorCodeMapSupplierIdMap = getOpinionFactorCodeMapSupplierIdMap(tenderProjectEntity.getId());
		Map<String, AuthUser> userMap = getExpertAndWorkerUserMap(tenderProjectEntity.getId());
		for (Supplier supplier : supplierList) {
			Element supplierElement = supplierListElement.addElement("supplier");
			supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName()));
			supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
			supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
			supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
			Map<String, EvaluationGroup> groupTypeMap = groupTypeMapSupplierMap.get(supplier.getId());
			Map<String, SupplierEvaluationFactor> opinionFactorCodeMap = opinionFactorCodeMapSupplierIdMap.get(supplier.getId());
			if (null == opinionFactorCodeMap) {
				opinionFactorCodeMap = new HashMap<String, SupplierEvaluationFactor>();
			}
			setBusinessToClearBidContent(supplierElement.addElement("business"), groupTypeMap, opinionFactorCodeMap, userMap);
			setTechnologyToClearBidContent(supplierElement.addElement("technology"), groupTypeMap, opinionFactorCodeMap, userMap);
			setBidPriceToClearBidContent(supplierElement.addElement("priceCompare"), groupTypeMap, userMap, supplier);
		}
	}

	/**
	 * @Description: 获取用户名称
	 * @author chenxw
	 */
	private Map<String, AuthUser> getExpertAndWorkerUserMap(String tenderId) {
		Map<String, AuthUser> userMap = new HashMap<String, AuthUser>();
		
		if(null == allExpertList){
			allExpertList = expertService.getExpertList(tenderId, ExpertEnum.ALL);
		}
		if (CollectionUtils.isNotNull(allExpertList)) {
			for (Expert expert : allExpertList) {
				userMap.put(expert.getUserId(), expert.getUser());
			}
		}
		if(null == allWorkerList){
			if(null == workerService){
				workerService = new WorkerService();
			}
			allWorkerList = workerService.getWorkerList(false,tenderId, ExpertEnum.WORKER);
		}
		if (CollectionUtils.isNotNull(allWorkerList)) {
			for (Worker worker : allWorkerList) {
				userMap.put(worker.getUserId(), worker.getUser());
			}
		}
		return userMap;
	}
	
	/**
	 * @Description: 获取评议意见
	 * @author chenxw
	 * @param tenderId 
	 * @return
	 */
	private Map<String, Map<String, SupplierEvaluationFactor>> getOpinionFactorCodeMapSupplierIdMap(String tenderId) {
		if(null == supplierEvaluationFactorService){
			supplierEvaluationFactorService = new SupplierEvaluationFactorService();
		}
		List<SupplierEvaluationFactor> evalFactorResultList = supplierEvaluationFactorService.getEntityListByTenderId(tenderId);
		if (CollectionUtils.isNull(evalFactorResultList)) {
			return new HashMap<String, Map<String, SupplierEvaluationFactor>>();
		}
		Map<String, Map<String, SupplierEvaluationFactor>> opinionFactorCodeMapSupplierIdMap = new HashMap<String, Map<String, SupplierEvaluationFactor>>();
		for (SupplierEvaluationFactor supplierEvaluationFactor : evalFactorResultList) {
			String factorCode = supplierEvaluationFactor.getFactorCode();
			String supplierId = supplierEvaluationFactor.getSupplierId();
			if (opinionFactorCodeMapSupplierIdMap.containsKey(supplierId)) {
				opinionFactorCodeMapSupplierIdMap.get(supplierId).put(factorCode, supplierEvaluationFactor);
			} else {
				Map<String, SupplierEvaluationFactor> opinionFactorCodeMap = new HashMap<String, SupplierEvaluationFactor>();
				opinionFactorCodeMap.put(factorCode, supplierEvaluationFactor);
				opinionFactorCodeMapSupplierIdMap.put(supplierId, opinionFactorCodeMap);
			}
		}
		return opinionFactorCodeMapSupplierIdMap;
	}
	
	/**
	 * @Description: 添加评标类型节点
	 * @author chenxw
	 * @param evalBidTypeElement
	 * @param groupTypeMap
	 * @param opinionFactorCodeMap
	 * @param userMap 
	 */
	private void setBusinessToClearBidContent(Element evalBidTypeElement, Map<String, EvaluationGroup> groupTypeMap, Map<String, SupplierEvaluationFactor> opinionFactorCodeMap, Map<String, AuthUser> userMap) {
		if (null == groupTypeMap) {
			return;
		}
		EvaluationGroup evaluationGroup = groupTypeMap.get(EvaluationFactorEnum.EVAL_BID_BUS);
		if (null == evaluationGroup) {
			return;
		}
		AuthUser user = userMap.get(evaluationGroup.getUserId());
		if (null == user) {
			return;
		}
		evalBidTypeElement.addElement("username").setText(XmlUtils.getXmlText(user.getUserName()));
		evalBidTypeElement.addElement("userIdCard").setText(XmlUtils.getXmlText(user.getUserIdcard()));
		setFactorToClearBidContent(evalBidTypeElement.addElement("factorList"), EvaluationFactorEnum.EVAL_BID_BUS, opinionFactorCodeMap);
	}
	
	/**
	 * @Description: 添加评标类型节点
	 * @author chenxw
	 * @param evalBidTypeElement
	 * @param groupTypeMap
	 * @param opinionFactorCodeMap
	 * @param userMap 
	 */
	private void setTechnologyToClearBidContent(Element evalBidTypeElement, Map<String, EvaluationGroup> groupTypeMap, Map<String, SupplierEvaluationFactor> opinionFactorCodeMap, Map<String, AuthUser> userMap) {
		if (null == groupTypeMap) {
			return;
		}
		EvaluationGroup evaluationGroup = groupTypeMap.get(EvaluationFactorEnum.EVAL_BID_TEC);
		if (null == evaluationGroup) {
			return;
		}
		AuthUser user = userMap.get(evaluationGroup.getUserId());
		if (null == user) {
			return;
		}
		evalBidTypeElement.addElement("username").setText(XmlUtils.getXmlText(user.getUserName()));
		evalBidTypeElement.addElement("userIdCard").setText(XmlUtils.getXmlText(user.getUserIdcard()));
		setFactorToClearBidContent(evalBidTypeElement.addElement("factorList"), EvaluationFactorEnum.EVAL_BID_TEC, opinionFactorCodeMap);
	}
	
	/**
	 * @Description: 添加评标类型节点
	 * @author chenxw
	 * @param evalBidTypeElement
	 * @param groupTypeMap
	 * @param supplier 
	 */
	private void setBidPriceToClearBidContent(Element evalBidTypeElement, Map<String, EvaluationGroup> groupTypeMap, Map<String, AuthUser> userMap, Supplier supplier) {
		if (null == groupTypeMap) {
			return;
		}
		EvaluationGroup evaluationGroup = groupTypeMap.get(EvaluationFactorEnum.EVAL_BID_PRICE);
		if (null == evaluationGroup) {
			return;
		}
		AuthUser user = userMap.get(evaluationGroup.getUserId());
		if (null == user) {
			return;
		}
		evalBidTypeElement.addElement("username").setText(XmlUtils.getXmlText(user.getUserName()));
		evalBidTypeElement.addElement("userIdCard").setText(XmlUtils.getXmlText(user.getUserIdcard()));
		
		SupplierOpeningResult supplierOpeningResult = supplier.getSupplierOpeningResult();
		BigDecimal bidPrice = null;
		BigDecimal finalBidPrice = null;
		BigDecimal evaluationPrice = null;
		BigDecimal modifyPrice = null;
		String modifyReason = null;
		if (null != supplierOpeningResult) {
			bidPrice = supplierOpeningResult.getBidPrice();
			finalBidPrice = supplierOpeningResult.getBidPrice(supplierOpeningResult.getFinalBidPrice());
			evaluationPrice = supplierOpeningResult.getEvaluationPrice();
			modifyPrice = BigDecimalUtils.sub(evaluationPrice, bidPrice);
			modifyReason = supplierOpeningResult.getModifyReason();
			// 投标价币种
			evalBidTypeElement.addElement("currencyCode").setText(tenderProjectRuleEntity.getCurrencyCode());
			// 投标价单位
			evalBidTypeElement.addElement("priceUnit").setText(XmlUtils.getXmlText(supplierOpeningResult.getPriceUnitCN(tenderProjectRuleEntity.getPriceUnitUseDefault())));
			// 投标价单位类型
			evalBidTypeElement.addElement("priceUnitType").setText(XmlUtils.getXmlText(CommonEnum.getPriceUnitType(supplierOpeningResult.getPriceUnitCN(tenderProjectRuleEntity.getPriceUnitUseDefault()))));
		}else {
			evalBidTypeElement.addElement("currencyCode").setText(BidPriceEnum.CUR_CODE);
			evalBidTypeElement.addElement("priceUnit").setText(XmlUtils.getXmlText(tenderProjectRuleEntity.getPriceUnitUseDefault()));
			evalBidTypeElement.addElement("priceUnitType").setText(XmlUtils.getXmlText(CommonEnum.getPriceUnitType(tenderProjectRuleEntity.getPriceUnitUseDefault())));
		}
		
		evalBidTypeElement.addElement("bidPrice").setText(XmlUtils.getXmlText(bidPrice));
		evalBidTypeElement.addElement("finalBidPrice").setText(XmlUtils.getXmlText(finalBidPrice));
		evalBidTypeElement.addElement("evaluationPrice").setText(XmlUtils.getXmlText(evaluationPrice));
		evalBidTypeElement.addElement("modifyPrice").setText(XmlUtils.getXmlText(modifyPrice));
		evalBidTypeElement.addElement("modifyReason").setText(XmlUtils.getXmlText(modifyReason));
		
	}
	
	/**
	 * @Description: 添加指标节点
	 * @author chenxw
	 * @param factorListElement
	 * @param evalBidType
	 * @param opinionFactorCodeMap 
	 */
	private void setFactorToClearBidContent(Element factorListElement, final String evalBidType, Map<String, SupplierEvaluationFactor> opinionFactorCodeMap) {
		if(null == allEvaluationFactorList){
			allEvaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProjectEntity.getId(), null);
		}
//		CollectionUtils.filter(allEvaluationFactorList, new CollectionUtils.Filter<EvaluationFactor>() {
//			public boolean select(EvaluationFactor t) {
//				return evalBidType.equals(t.getEvalBidType());
//			}
//		});
		if (CollectionUtils.isNull(allEvaluationFactorList)) {
			return;
		}
		for (EvaluationFactor evaluationFactor : allEvaluationFactorList) {
			if(evalBidType.equals(evaluationFactor.getEvalBidType())){
				
				addFactorElement(factorListElement, evaluationFactor, opinionFactorCodeMap);
			}
		}
	}

	/**
	 * @Description: 递归添加指标节点
	 * @author chenxw
	 * @param factorListElement
	 * @param evaluationFactor
	 * @param opinionFactorCodeMap 
	 */
	private void addFactorElement(Element factorListElement, EvaluationFactor evaluationFactor, Map<String, SupplierEvaluationFactor> opinionFactorCodeMap) {
		Element factorElement = factorListElement.addElement("factor");
		factorElement.addElement("id").setText(ObjectUtils.getObjString(evaluationFactor.getId()));
		factorElement.addElement("parentId").setText(ObjectUtils.getObjString(evaluationFactor.getParentId()));
		factorElement.addElement("name").setText(XmlUtils.getXmlText(evaluationFactor.getFactorName()));
		factorElement.addElement("code").setText(XmlUtils.getXmlText(evaluationFactor.getFactorCode()));
		String opinion = null;
		SupplierEvaluationFactor supplierEvaluationFactor = opinionFactorCodeMap.get(evaluationFactor.getFactorCode());
		if (null != supplierEvaluationFactor) {
			opinion = supplierEvaluationFactor.getOpinion();
		}
		factorElement.addElement("opinion").setText(XmlUtils.getXmlText(opinion));
		if (CollectionUtils.isNull(evaluationFactor.getChildFactorList())) {
			return;
		}
		for (EvaluationFactor childFactor : evaluationFactor.getChildFactorList()) {
			addFactorElement(factorListElement, childFactor, opinionFactorCodeMap);
		}
	}

	/**
	 * 生成评标步骤
	 * @param path
	 * @return
	 */
	private boolean createEvaluationFactorsxml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("evaluationFactor");
			setComplianceFactors(rootElement);
			setscoreFactors(rootElement);
			setPriceFactors(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	
	
	/**
	 * @Description: 价格评审节点组装
	 * @author guoyr
	 * @param rootElement 
	 */
	private void setPriceFactors(Element rootElement){
		 Element complianceFactorsElement = rootElement.addElement("priceFactors");
		 List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProjectEntity.getId(), EvaluationFactorEnum.AUDIT_PRICE);
		 if(null != evaluationFactorList){
			 for(EvaluationFactor evaluationFactor : evaluationFactorList){
				 setEvaluationPriceFactor(complianceFactorsElement, evaluationFactor);
			 }
		 }
	}
	
	/**
	 * @Description: 价格评审指标组装
	 * @author guoyr
	 * @param complianceFactorsElement
	 * @param evaluationFactor 
	 */
	private void setEvaluationPriceFactor(Element complianceFactorsElement, EvaluationFactor evaluationFactor){
		Element factorElement = complianceFactorsElement.addElement("factor");
		factorElement.addElement("id").setText(evaluationFactor.getId());
		factorElement.addElement("name").setText(XmlUtils.getXmlText(evaluationFactor.getFactorName()));
		factorElement.addElement("code").setText(XmlUtils.getXmlText(evaluationFactor.getFactorCode()));
		factorElement.addElement("score").setText(evaluationFactor.getFactorScore()+"");
		factorElement.addElement("weight").setText(XmlUtils.getXmlText(evaluationFactor.getFactorWeight()));
		factorElement.addElement("memo").setText(XmlUtils.getXmlText(evaluationFactor.getMemo()));
		setPriceChildren(factorElement, evaluationFactor);
	}
	/**
	 * @Description: 价格评审子集指标组装
	 * @author guoyr
	 * @param factorElement
	 * @param evaluationFactor 
	 */
	private void setPriceChildren(Element factorElement, EvaluationFactor evaluationFactor){
		List<EvaluationFactor> listEvaluationFactor = evaluationFactor.getChildFactorList();
		Element fchildFactorListElement = factorElement.addElement("childFactorList");
		for(EvaluationFactor factor : listEvaluationFactor){
			setEvaluationPriceFactor(fchildFactorListElement, factor);
		}
	}
	
	/**
	 * @Description: 打分评审节点组装
	 * @author guoyr
	 * @param rootElement 
	 */
	private void setscoreFactors(Element rootElement){//打分评审节点
		 Element complianceFactorsElement = rootElement.addElement("scoreFactors");
		 List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProjectEntity.getId(), EvaluationFactorEnum.AUDIT_SCORE);
		 if(null != evaluationFactorList){
			 for(EvaluationFactor evaluationFactor : evaluationFactorList){
				 setEvaluationScoreFactor(complianceFactorsElement, evaluationFactor);
			 }
		 }
	}
	/**
	 * @Description: 打分评审层级组装
	 * @author guoyr
	 * @param complianceFactorsElement
	 * @param evaluationFactor 
	 */
	private void setEvaluationScoreFactor(Element complianceFactorsElement, EvaluationFactor evaluationFactor){
		Element factorElement = complianceFactorsElement.addElement("factor");
		factorElement.addElement("id").setText(evaluationFactor.getId());
		factorElement.addElement("name").setText(XmlUtils.getXmlText(evaluationFactor.getFactorName()));
		factorElement.addElement("code").setText(XmlUtils.getXmlText(evaluationFactor.getFactorCode()));
		factorElement.addElement("score").setText(evaluationFactor.getFactorScore()+"");
		factorElement.addElement("minScore").setText(null == evaluationFactor.getFactorMinScore() ? "" : evaluationFactor.getFactorMinScore()+"");
		factorElement.addElement("maxScore").setText(null == evaluationFactor.getFactorMaxScore() ? "" : evaluationFactor.getFactorMaxScore()+"");
		factorElement.addElement("weight").setText(null == evaluationFactor.getFactorWeight() ? "" : evaluationFactor.getFactorWeight()+"");
		factorElement.addElement("objective").setText(null == evaluationFactor.getObjective() ? "" : evaluationFactor.getObjective());
		factorElement.addElement("factorType").setText(null == evaluationFactor.getFactorType()? "" : evaluationFactor.getFactorType());
		factorElement.addElement("memo").setText(XmlUtils.getXmlText(evaluationFactor.getMemo()));
		setScoreOptions(factorElement, evaluationFactor);
		setScoreChildren(factorElement, evaluationFactor);
	}
	
	/**
	 * @Description:打分评审节点评审指标值组装
	 * @author guoyr
	 * @param factorElement
	 * @param evaluationFactor 
	 */
	private void setScoreOptions(Element factorElement, EvaluationFactor evaluationFactor){
		Element optionsElement = factorElement.addElement("options");
		@SuppressWarnings("unchecked")
		List<ScoreItem> itemList = (List<ScoreItem>)SerializeUtils.deserializeObject(evaluationFactor.getObjectiveItem());
		if(null != itemList && itemList.size() > 0){
			for(ScoreItem item : itemList){
				BigDecimal score = BigDecimal.ZERO;
				if(null != item.getScore()){
					score = item.getScore();
				}
				String name = null == item.getName() ? "" : item.getName();
				Element objectiveElement = optionsElement.addElement("option");
				objectiveElement.addElement("name").setText(XmlUtils.getXmlText(name));
				objectiveElement.addElement("value").setText(score + "");
			}
		}else{
			Element objectiveElement = optionsElement.addElement("option");
			objectiveElement.addElement("name").setText("");
			objectiveElement.addElement("value").setText( "");
		}
	}

	private void setScoreChildren(Element factorElement, EvaluationFactor evaluationFactor){
		List<EvaluationFactor> listEvaluationFactor = evaluationFactor.getChildFactorList();
		Element fchildFactorListElement = factorElement.addElement("childFactorList");
		for(EvaluationFactor factor : listEvaluationFactor){
			setEvaluationScoreFactor(fchildFactorListElement, factor);
		}
	}
	 /**
	 * @Description:生成符合性评审节点
	 * @author guoyr
	 * @param rootElement 
	 */
	private void setComplianceFactors(Element rootElement){//符合性评审节点
		 Element complianceFactorsElement = rootElement.addElement("complianceFactors");
//		 先查找符合性评审的节点信息
		 List<EvaluationFactor> evaluationFactorList = evaluationFactorService.getAllEvaluationFactorList(tenderProjectEntity.getId(), EvaluationFactorEnum.AUDIT_COMPLIANCE);
		 if(null != evaluationFactorList){
			 for(EvaluationFactor evaluationFactor : evaluationFactorList){
				 setEvaluationComplianceFactor(complianceFactorsElement, evaluationFactor);
			 }
		 }
	 }
	
	/**
	 * @Description: 符合性节点层级结构组装
	 * @author guoyr
	 * @param complianceFactorsElement
	 * @param evaluationFactor 
	 */
	private void setEvaluationComplianceFactor(Element complianceFactorsElement, EvaluationFactor evaluationFactor){
		Element factorElement = complianceFactorsElement.addElement("factor");
		//factorElement.addElement("id").setText(evaluationFactor.getId());
		factorElement.addElement("id").setText(UuidUtils.getUUID());
		factorElement.addElement("name").setText(XmlUtils.getXmlText(evaluationFactor.getFactorName()));
		factorElement.addElement("code").setText(XmlUtils.getXmlText(evaluationFactor.getFactorCode()));
		factorElement.addElement("objective").setText(null == evaluationFactor.getObjective() ? "" : evaluationFactor.getObjective());
		factorElement.addElement("memo").setText(XmlUtils.getXmlText(evaluationFactor.getMemo()));
		setComplianceOptions(factorElement, evaluationFactor);
		setComplianceChildren(factorElement, evaluationFactor);
	}
	
	/**
	 * @Description: 符合性评审节点评审指标符合性值组装
	 * @author guoyr
	 * @param factorElement
	 * @param evaluationFactor 
	 */
	private void setComplianceOptions(Element factorElement, EvaluationFactor evaluationFactor){
		Element optionsElement = factorElement.addElement("options");
//		"评审内容[符合,不符合]"
		if(null != evaluationFactor.getEvalContent() && "".equals(evaluationFactor.getEvalContent())){
			String[] evalContentValues = evaluationFactor.getEvalContent().split(",");
			if(evalContentValues.length == 2){
				Element yesOptionElement = optionsElement.addElement("option");
				yesOptionElement.addElement("name").setText(XmlUtils.getXmlText(evalContentValues[0]));
				yesOptionElement.addElement("value").setText(EvaluationFactorEnum.CONFORM);
				Element noOptionElement = optionsElement.addElement("option");
				noOptionElement.addElement("name").setText(XmlUtils.getXmlText(evalContentValues[1]));
				noOptionElement.addElement("value").setText(EvaluationFactorEnum.UNCONFORM);
			}else{
				Element yesOptionElement = optionsElement.addElement("option");
				yesOptionElement.addElement("name").setText("");
				yesOptionElement.addElement("value").setText("");
			}
		}else{
			Element yesOptionElement = optionsElement.addElement("option");
			yesOptionElement.addElement("name").setText("");
			yesOptionElement.addElement("value").setText("");
		}
	}
	
	/**
	 * @Description: 符合性评审节点评审指标父子集组装
	 * @author guoyr
	 * @param factorElement
	 * @param evaluationFactor 
	 */
	private void setComplianceChildren(Element factorElement, EvaluationFactor evaluationFactor){
		List<EvaluationFactor> listEvaluationFactor = evaluationFactor.getChildFactorList();
		Element fchildFactorListElement = factorElement.addElement("childFactorList");
		for(EvaluationFactor factor : listEvaluationFactor){
			setEvaluationComplianceFactor(fchildFactorListElement, factor);
		}
	}
	
	/**
	 * 生成评标结果FactorsEvalResult.xml
	 * @param path
	 * @return
	 */
	private boolean createFactorsEvalResultxml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("factorsEvalResult");
			setEvaluationStepToFactorsEvalResultXML(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	/**
	 * @Description: FactorsEvalResultXML中的评审节点信息列表
	 * @author guoyr
	 * @param rootElement 
	 */
	private void setEvaluationStepToFactorsEvalResultXML(Element rootElement){
		if(null == evaluationStepList){
			evaluationStepList = evaluationStepService.getEvaluationStepList(tenderProjectEntity.getId());
		}
		if(null != evaluationStepList){
			List<String> supplierStepList = new ArrayList<String>();
			supplierStepList.add(EvaluationStepEnum.COMPLIANCE);
			supplierStepList.add(EvaluationStepEnum.DETAIL);
			supplierStepList.add(EvaluationStepEnum.PRICE);
			supplierStepList.add(EvaluationStepEnum.BILL);
			for(EvaluationStep evaluationStep : evaluationStepList){
				if(supplierStepList.contains(evaluationStep.getStepType())){
					Element evalStepElement = rootElement.addElement("evalStep");
					evalStepElement.addElement("stepId").setText(evaluationStep.getId());
					evalStepElement.addElement("stepName").setText(XmlUtils.getXmlText(evaluationStep.getStepName()));
					evalStepElement.addElement("stepType").setText(evaluationStep.getStepType());
					evalStepElement.addElement("evalBidType").setText(XmlUtils.getXmlText(evaluationStep.getEvalBidType()));
					setSupplierToFactorsEvalResultXML(evalStepElement, evaluationStep);
				}
			}
		}
	}
	
	/**
	 * @Description: FactorsEvalResultXML中的供应商信息列表
	 * @author guoyr
	 * @param evalStepElement
	 * @param evaluationStep 
	 */
	private void setSupplierToFactorsEvalResultXML(Element evalStepElement, EvaluationStep evaluationStep){
		if(null != supplierList){
			
			for(Supplier supplier : supplierList){
				Element supplierElement = evalStepElement.addElement("supplier");
				supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName()));
				supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
				supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				String evaluationScore = "";
				String evaluationFinalScore = "";
				String accessment = "";
				String sortNo = "";
				SupplierEvaluationResult supplierEvaluationResult = supplierEvaluationResultMap.get(supplier.getId());
				if(null != supplierEvaluationResult){
					evaluationScore = null != supplierEvaluationResult.getEvaluationScore() ? supplierEvaluationResult.getEvaluationScore().toString() : "";
					evaluationFinalScore = null != supplierEvaluationResult.getEvaluationFinalScore() ? supplierEvaluationResult.getEvaluationFinalScore().toString() : "";
					accessment = null != supplierEvaluationResult.getAccessment() ? supplierEvaluationResult.getAccessment() : "";
					sortNo = supplierEvaluationResult.getSortNo() > 0 ? supplierEvaluationResult.getSortNo() + "" : "";
				}
				supplierElement.addElement("evaluationScore").setText(evaluationScore);
				supplierElement.addElement("evaluationFinalScore").setText(evaluationFinalScore);
				supplierElement.addElement("accessment").setText(accessment);
				supplierElement.addElement("sortNo").setText(sortNo);
				setExpertToFactorsEvalResultXML(supplierElement, evaluationStep, supplier.getId());
				
			}
		}
	}
	
	/**
	 * @Description: FactorsEvalResultXML中 对应评审节点中的评审专家列表
	 * @author guoyr
	 * @param supplierElement
	 * @param evaluationStep 
	 */
	private void setExpertToFactorsEvalResultXML(Element supplierElement, EvaluationStep evaluationStep, String supplierId){
		if (evaluationStep.getStepType().equals(EvaluationStepEnum.BILL)) {
			setFactorResultToFactorsEvalResultXML(supplierElement, evaluationStep, null ,supplierId);
		} else {
			List<Expert> expertList = stepExpertListMap.get(evaluationStep.getId());
			if(null == expertList){
				expertList = expertService.getEvaluationStepExpertList(tenderProjectEntity.getId(), evaluationStep);
				stepExpertListMap.put(evaluationStep.getId(), expertList);
			}
			if(null != expertList){
				for(Expert expert : expertList){
					Element expertElement = supplierElement.addElement("expert");
					String expertId = "";
					String account = "";
					String expertName = "";
					if(null != expert.getUser()){
						expertId = expert.getUser().getId();
						account = expert.getUser().getUserAccount();
						expertName = expert.getUser().getUserName();
					}
					expertElement.addElement("expertId").setText(XmlUtils.getXmlText(expertId));
					expertElement.addElement("account").setText(XmlUtils.getXmlText(account));
					expertElement.addElement("expertName").setText(XmlUtils.getXmlText(expertName));
					setFactorResultToFactorsEvalResultXML(expertElement, evaluationStep, expert ,supplierId);
				}
			}
		}
	}
	
	/**
	 * @Description: FactorsEvalResultXML中 专家对供应商评审指标评审得分
	 * @author guoyr
	 * @param expertElement
	 * @param evaluationStep
	 * @param expert
	 * @param supplierId 
	 */
	public void setFactorResultToFactorsEvalResultXML(Element expertElement, EvaluationStep evaluationStep, Expert expert ,String supplierId){
		List<EvaluationFactor> evaluationFactorList = stepEvaluationFactorListMap.get(evaluationStep.getId());
		if(null == evaluationFactorList){
			evaluationFactorList = evaluationFactorService.getEvaluationStepFactorList(tenderProjectEntity.getId(), evaluationStep, true);
			stepEvaluationFactorListMap.put(evaluationStep.getId(), evaluationFactorList);
		}
		if(null != evaluationFactorList){
			String userId = null;
			if (null != expert) {
				userId = expert.getUser().getId();
			}
			List<EvaluationFactorResult> evaluationFactorResultList = evaluationFactorResultService.getExpertEvaluationFactorResult(tenderProjectEntity.getId(), evaluationStep.getId(), userId, supplierId);
			Map<String,EvaluationFactorResult>  evaluationFactorResultMap = new HashMap<String,EvaluationFactorResult>();
			if(null != evaluationFactorResultList && evaluationFactorResultList.size() > 0){
				for(EvaluationFactorResult factorResult : evaluationFactorResultList){
					evaluationFactorResultMap.put(factorResult.getFactorId(),factorResult);
				}
			}
			for(EvaluationFactor evaluationFactor : evaluationFactorList){
				Element factorElement = expertElement.addElement("factor");
				factorElement.addElement("id").setText(evaluationFactor.getId());
				factorElement.addElement("name").setText(XmlUtils.getXmlText(evaluationFactor.getFactorName()));
				factorElement.addElement("code").setText(XmlUtils.getXmlText(evaluationFactor.getFactorCode()));
				String evaluationScore = "";
				String evaluationFinalScore = "";
				String evaluationResult = "";
				String evaluationOpinion = "";

				EvaluationFactorResult factorResult  = evaluationFactorResultMap.get(evaluationFactor.getId());
				if(null != factorResult){
					if(ObjectUtils.equals(supplierId, factorResult.getSupplierId()) && ObjectUtils.equals(evaluationFactor.getId(), factorResult.getFactorId())){
						evaluationScore = null != factorResult.getEvaluationScore() ? factorResult.getEvaluationScore().toString() : "";
						evaluationFinalScore = null != factorResult.getEvaluationFinalScore() ? factorResult.getEvaluationFinalScore().toString() : "";
						evaluationResult = null != factorResult.getEvaluationResult() ? factorResult.getEvaluationResult() : "";
						evaluationOpinion = null != factorResult.getEvaluationOpinion() ? factorResult.getEvaluationOpinion() : "";
					}
				}
				factorElement.addElement("evaluationScore").setText(evaluationScore);
				factorElement.addElement("evaluationFinalScore").setText(evaluationFinalScore);
				factorElement.addElement("evaluationResult").setText(evaluationResult);
				factorElement.addElement("evaluationOpinion").setText(XmlUtils.getXmlText(evaluationOpinion));
			}
		}
	}
	/**
	 * 生成评标步骤EvaluationStep.Xml
	 * @param path
	 * @return
	 */
	private boolean createupLoadEvaluationStepXml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("evaluationStepList");
			setStepToEvaluationStepXml(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	private void setStepToEvaluationStepXml(Element rootElement){
		//获取当前项目下除去专家签到，价格评审，推荐候选人之外的所有评审节点
		String service = PropertiesUtils.getProperty(ConfigConstants.NET_SERVICE, "");
		if(null == evaluationStepList){
			evaluationStepList = evaluationStepService.getEvaluationStepList(tenderProjectEntity.getId());
		}
		if(null != evaluationStepList){
			for(EvaluationStep evaluationStep : evaluationStepList){
				if(evaluationStep.getStepType().equals(EvaluationStepEnum.PRE_EVALUATION)){
					if(!service.equals("ZDJService")){
						continue;
					}
				}
				
				Element evaluationFactorEemelent = rootElement.addElement("evaluationStep");
				evaluationFactorEemelent.addElement("stepId").setText(evaluationStep.getId());
				//evaluationFactorEemelent.addElement("stepId").setText(UuidUtils.getUUID());
				evaluationFactorEemelent.addElement("stepName").setText(XmlUtils.getXmlText(evaluationStep.getStepName()));
				evaluationFactorEemelent.addElement("darkEvaluation").setText(XmlUtils.getXmlText(evaluationStep.getDarkEvaluation()));
				evaluationFactorEemelent.addElement("stepType").setText(XmlUtils.getXmlText(evaluationStep.getStepType()));
				evaluationFactorEemelent.addElement("evalBidType").setText(XmlUtils.getXmlText(evaluationStep.getEvalBidType()));
				evaluationFactorEemelent.addElement("stepMemo").setText(XmlUtils.getXmlText(evaluationStep.getStepMemo()));
				evaluationFactorEemelent.addElement("sortNo").setText(evaluationStep.getSortNo()+"");
				Element expertListElement = evaluationFactorEemelent.addElement("expertList");
				if(EvaluationStepEnum.DETAIL.equals(evaluationStep.getStepType()) || EvaluationStepEnum.COMPLIANCE.equals(evaluationStep.getStepType())){
					setExpertToEvaluationStepXml(expertListElement, evaluationStep);
				}else if(EvaluationStepEnum.SIGIN.equals(evaluationStep.getStepType())){
					setExpertByExpertXML(expertListElement);
				}
				
			}
		}
	}
	
	/**
	 * @Description: EvaluationStepXml添加评审专家
	 * @author guoyr
	 * @param expertListElement
	 * @param evaluationStep 
	 */
	private void setExpertToEvaluationStepXml(Element expertListElement, EvaluationStep evaluationStep){
		//查询当前评审步骤下的评审专家
		List<Expert> expertList = stepExpertListMap.get(evaluationStep.getId());
		if(null == expertList){
			expertList = expertService.getEvaluationStepExpertList(tenderProjectEntity.getId(), evaluationStep);
			stepExpertListMap.put(evaluationStep.getId(), expertList);
		}
		if(null != expertList){
			
			for(Expert expert : expertList){
				Element expertElement = expertListElement.addElement("expert");
				expertElement.addElement("expertId").setText(XmlUtils.getXmlText(expert.getUser().getId()));
				expertElement.addElement("expertName").setText(XmlUtils.getXmlText(expert.getUser().getUserName()));
				expertElement.addElement("expertAccount").setText(XmlUtils.getXmlText(expert.getUser().getUserAccount()));
			}
		}
	}
	/**
	 * 生成评审专家Expert.xml
	 * @param path
	 * @return
	 */
	private boolean createExpertXml(String path){
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("expertList");
			setExpertByExpertXML(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;
		} catch (Exception e) {
			LOG.error("", e);
			return false;
		}
	}
	
	/**
	 * @Description: 专家xml专家信息
	 * @author guoyr
	 * @param rootElement 
	 */
	private void setExpertByExpertXML(Element rootElement){
		if(null == allExpertList){
			allExpertList = expertService.getExpertList(tenderProjectEntity.getId(), ExpertEnum.ALL);
		}
		if(null != allExpertList){
			for(Expert expert : allExpertList){
				Element expertElement = rootElement.addElement("expert");
				AuthUser user = expert.getUser();
				if(null == user){
					user = new AuthUser();
				}
				expertElement.addElement("expertId").setText(user.getId());
				expertElement.addElement("account").setText(user.getUserAccount());
				expertElement.addElement("expertName").setText(XmlUtils.getXmlText(user.getUserName()));
				expertElement.addElement("expertType").setText(null != expert.getExpertType() ? expert.getExpertType() : "");
				expertElement.addElement("isLeader").setText(XmlUtils.getXmlText(expert.getIsLeader()));
				expertElement.addElement("idCard").setText(null != user.getUserIdcard() ? user.getUserIdcard() :"");
				expertElement.addElement("phone").setText(null != user.getPhone() ? user.getPhone() : "");
				expertElement.addElement("professionalTitle").setText(XmlUtils.getXmlText(user.getProfessionalTitle()));
				expertElement.addElement("specialty").setText(XmlUtils.getXmlText(user.getSpecialty()));
				expertElement.addElement("company").setText(XmlUtils.getXmlText(user.getCompany()));
				expertElement.addElement("areaCode").setText(XmlUtils.getXmlText(user.getAreaCode()));
				expertElement.addElement("signType").setText(null != expert.getSignType() ? expert.getSignType() :"");
				expertElement.addElement("signResult").setText(XmlUtils.getXmlText(expert.getSignResult()));
				String signTime = "";
				if(null != expert.getSignTime()){
					signTime = format.format(expert.getSignTime());
				}
				expertElement.addElement("signTime").setText(signTime);
			}
		}
	}
	
	
	/**
	 * @Description 关联关系信息
	 * @param path
	 * @return
	 */
	private boolean createAssociationOpinion(String path) {
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("associationOpinion");
			setAssociationOpinionXML(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;	
		} catch (Exception e) {
			LOG.error("", e);
		}
		return false;
	}
	
	private void setAssociationOpinionXML(Element rootElement) {
		Element suppliersElement = rootElement.addElement("supplierList");
		List<EvaluationStep> associationStepList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), EvaluationStepEnum.ASSOCIATION_QUERY);
		if(null != associationStepList && associationStepList.size() > 0) {
			EvaluationStep step = associationStepList.get(0);
			List<SupplierEvaluationStep> resultList = supplierEvaluationStepService.getSupplierEvaluationStepByTenderIdAndStepId(tenderProjectEntity.getId(), step.getId());
			Map<String,SupplierEvaluationStep> resultMap = new HashMap<String,SupplierEvaluationStep>();
			if(null != resultList && resultList.size() > 0) {
				for(SupplierEvaluationStep result : resultList) {
					resultMap.put(result.getSupplierId(), result);
				}
			}
			
			List<Supplier> supplierList = supplierService.getEvaluationStepSupplierList(tenderProjectEntity.getId(), step);
			if(null != supplierList && supplierList.size() > 0) {
				for(Supplier supplier : supplierList) {
					Element supplierElement = suppliersElement.addElement("supplier");
					supplierElement.addElement("supplierId").setText(supplier.getId());
					supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName().toString()));
					supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
					supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
					supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
					SupplierEvaluationStep result = resultMap.get(supplier.getId());
					if(null != result) {
						supplierElement.addElement("result").setText(result.getAccessment().equals(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED) ? "符合":"不符合");
					}
				}
			}
		}
	}
	
	
	/**
	 * @Description: 生成多轮报价XML
	 * @author wangxiang 
	 */
	private boolean createMultiRoundsBidPrice(String path) {
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("multiRoundsBidPrice");
			setBidPRiceBysupplierXML(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;	
		} catch (Exception e) {
			LOG.error("", e);
		}
		return false;
	}
	
	/**
	 * @Description: 供应商多轮报价结果
	 * @author wangxiang
	 * @param rootElement 
	 */
	private void setBidPRiceBysupplierXML(Element rootElement) {
		if (null != supplierList) {
			SupplierOpeningResult supplierOpeningResult = supplierList.size() > 0 ? supplierOpeningResultMap.get(supplierList.get(0).getId()) : null;
			rootElement.addElement("price_unit").setText(XmlUtils.getXmlText(null != tenderProjectRuleEntity.getPriceUnitUseDefault()? tenderProjectRuleEntity.getPriceUnitUseDefault() : ""));
			// 投标价币种
			rootElement.addElement("currencyCode").setText(null != supplierOpeningResult.getCurrencyCode()? supplierOpeningResult.getCurrencyCode() : tenderProjectRuleEntity.getCurrencyCode());
			// 投标价单位
			rootElement.addElement("priceUnit").setText(XmlUtils.getXmlText(supplierOpeningResult.getPriceUnitCN(tenderProjectRuleEntity.getPriceUnitUseDefault())));
			// 投标价单位类型
			rootElement.addElement("priceUnitType").setText(XmlUtils.getXmlText(CommonEnum.getPriceUnitType(supplierOpeningResult.getPriceUnitCN(tenderProjectRuleEntity.getPriceUnitUseDefault()))));
			Element suppliersElement = rootElement.addElement("supplierList");
			ListSortUtils<Supplier> listSortUtils = new ListSortUtils<Supplier>(supplierList, new Comparator<Supplier>() {
				public int compare(Supplier behindSupplier, Supplier frontSupplier) {
					SupplierOpeningResult frontRank = supplierOpeningResultMap.get(frontSupplier.getId());
					SupplierOpeningResult behindRank = supplierOpeningResultMap.get(behindSupplier.getId());
					return frontRank.getBidPrice().compareTo(behindRank.getBidPrice());
				}
			});
			
			Map<String, Supplier> supplierMap = CollectionUtils.toHashMap(supplierList, Supplier::getId);
			
			Comparator<BidPriceHisResult> comparator =  new Comparator<BidPriceHisResult>(){
				public int compare(BidPriceHisResult o1, BidPriceHisResult o2) {
					return o1.getBidPrice().compareTo(o2.getBidPrice());
				}
			};
			if(null == reBidPriceRoundService){
				reBidPriceRoundService = new ReBidPriceRoundService();
			}
			int round = reBidPriceRoundService.getMaxRound(tenderProjectEntity.getId());
			int[][] rankss = new int[supplierList.size()][round];
			if(null == bidPriceHisResultService){
				bidPriceHisResultService = new BidPriceHisResultService();
			}
			
			BidPrice bidPrice = null;
			List<BidPrice> bidPriceList = bidPriceService.getBidPriceFactorList(tenderProjectEntity.getId());
			if(null != bidPriceList && bidPriceList.size() > 0) {
				for(BidPrice _bidPrice : bidPriceList) {
					if(BidPriceEnum.IS_PRICE.equals(_bidPrice.getPriceType())) {
						bidPrice = _bidPrice;
						break;
					}
				}
			}
			
			for (int i = 1; i <= round; i++) {
				List<BidPriceHisResult> bidPriceHisResultRankList = bidPriceHisResultService.getBidPriceHisResultList(tenderProjectEntity.getId(), null != bidPrice ? bidPrice.getId() : null, i);
				ListSortUtils<BidPriceHisResult> supplierSortUtils = new ListSortUtils<BidPriceHisResult>(bidPriceHisResultRankList, comparator);
				for (BidPriceHisResult bidPriceHisResult_rank : bidPriceHisResultRankList) {
					Supplier supplier = supplierMap.get(bidPriceHisResult_rank.getSupplierId());
					if (null != supplier) {
						rankss[supplierList.indexOf(supplier)][i-1] = supplierSortUtils.getSortNo(bidPriceHisResult_rank);
					}
				}
			}
			
			int index = 0;
			
			List<BidPriceRound> bidPriceRoundList = reBidPriceRoundService.getBidPriceRoundList(tenderProjectEntity.getId());
			Map<String,BidPriceRound> roundMap = new HashMap<String,BidPriceRound>();
			for(BidPriceRound bidPriceRound : bidPriceRoundList) {
				roundMap.put(bidPriceRound.getRoundNo()+"", bidPriceRound);
			}
			for (Supplier supplier : supplierList) {
				Element supplierElement = suppliersElement.addElement("supplier");
				supplierElement.addElement("supplierId").setText(supplier.getId());
				supplierElement.addElement("supplierName").setText(XmlUtils.getXmlText(supplier.getSupplierName().toString()));
				supplierElement.addElement("orgCode").setText(XmlUtils.getXmlText(supplier.getOrgCode()));
				supplierElement.addElement("orgId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				supplierElement.addElement("mainId").setText(XmlUtils.getXmlText(supplier.getOrgId()));
				supplierElement.addElement("rank").setText(listSortUtils.getSortNo(supplier)+"");
				
				
				List<BidPriceHisResult>	bidPriceHisResultList = bidPriceHisResultService.getBidPriceHisResultList(tenderProjectEntity.getId(), null != bidPrice ? bidPrice.getId() : null , supplier.getId());
				if(null != bidPriceHisResultList){
					Element roundElement = 	supplierElement.addElement("roundList");
					for(BidPriceHisResult bidPriceHisResult : bidPriceHisResultList){
						Element roundsElement = roundElement.addElement("bidPriceRound");
						roundsElement.addElement("round").setText(bidPriceHisResult.getBidPriceRound()+"");
						BidPriceRound bidPriceRound = roundMap.get(bidPriceHisResult.getBidPriceRound()+"");
						roundsElement.addElement("offerEndDateTime").setText(null != bidPriceRound ? DateUtils.getTimestampFormat(bidPriceRound.getRoundEndTime()) : "");
						roundsElement.addElement("roundName").setText(XmlUtils.getXmlText(bidPriceHisResult.getRoundName().toString()));
						roundsElement.addElement("rank").setText(String.valueOf(rankss[index][bidPriceHisResult.getBidPriceRound()-1]));
						roundsElement.addElement("bidPrice").setText(XmlUtils.getXmlText(bidPriceHisResult.getBidPrice()));
						roundsElement.addElement("finalBidPrice").setText(XmlUtils.getXmlText(bidPriceHisResult.getBidPrice(bidPriceHisResult.getFinalBidPrice())));
						roundsElement.addElement("bidPriceMemo").setText(XmlUtils.getXmlText(null != bidPriceHisResult.getBidPriceMemo()? bidPriceHisResult.getBidPriceMemo() : ""));
					}
				}
				index++;
			}
		}
	}
	
	/**
	 * @Description: 生成废标意见XML
	 * @author wangxiang 
	 */
	private boolean createWasteBidReason(String path) {
		try {
			Document document = DocumentHelper.createDocument();
			Element rootElement = document.addElement("wastebidreason");
			setWastebidReasonXML(rootElement);
			XmlUtils.createXmlFile(document, path, XML_ENCODING);
			return true;	
		} catch (Exception e) {
			LOG.error("", e);
		}
		return false;
	}
	
	/**
	 * @Description: 废标意见
	 * @author wangxiang
	 * @param rootElement 
	 */
	private void setWastebidReasonXML(Element rootElement) {
		rootElement.addElement("name").setText(XmlUtils.getXmlText(tenderProjectEntity.getTenderName()));
		rootElement.addElement("code").setText(XmlUtils.getXmlText(tenderProjectEntity.getTenderNo()));
		rootElement.addElement("wasteBidType").setText(null != tenderProjectEntity.getEffectiveType()? tenderProjectEntity.getEffectiveType() : "01");
		rootElement.addElement("wasteBidReason").setText(XmlUtils.getXmlText(tenderProjectEntity.getEffectiveMemo()));
	}
	
	private void callBackMsg(String msg){
		if(null != callBack){
			callBack.info("  "+msg);
		}
	}
	private void callBackMsg(boolean bool, String msg){
		if(null != callBack){
			callBack.info((bool?"√":"×")+ msg);
		}
	}
	
	/**
	 * @Description: 
	 * @author guoyr
	 * @param expert
	 * @return 
	 */
	private List<EvaluationStep> getExpertEvaluationStepList(Expert expert) {
		if(null == evaluationStepExpertService){
			evaluationStepExpertService = new EvaluationStepExpertService();
		}
		// 获得所有的评标步骤
		if(null == evaluationStepList){
			evaluationStepList = evaluationStepService.getEvaluationStepList(tenderProjectEntity.getId());
		}
		List<EvaluationStep> returnEvaluationStepList = new ArrayList<EvaluationStep>();
		
		if (null != evaluationStepList && evaluationStepList.size() > 0) {
			
			// 获得当前专家指定评审的评标步骤
			List<String> customStepList = null;
			List<String> evalGroupStepList = null;
			for (int stepIndex = 0; stepIndex < evaluationStepList.size(); stepIndex++) {
				EvaluationStep evaluationStep = evaluationStepList.get(stepIndex);
				if (ObjectUtils.equals(evaluationStep.getStepType(), EvaluationStepEnum.SIGIN)) {
					//价格评审专家不参与评审
					continue;
				}
				
				if (ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.EXPERT_LEADER)) {
					if (!ObjectUtils.equals(expert.getIsLeader(), ExpertEnum.LEADER_YES)) {
						continue;
					}
				} else if (ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.OPERATOR)) {
					// 如果当前评标步骤节点是由项目经理操作
					continue;
				} else if (ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.CUSTOM)) {
					
					if(null == customStepList){
						customStepList = evaluationStepExpertService.finStepIdByTenderIdAndUserId(tenderProjectEntity.getId(), expert.getUser().getId());
					}
					
					// 如果该专家没有指定评标步骤或，在当前评标步骤没有指定给该专家
					if (null == customStepList || !customStepList.contains(evaluationStep.getId())) {
						continue;
					}
					
				} else if (ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.EVAL_BID_TYPE)) {
					if (null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_BUS)) {
						if ((expert.getEvalBidTypeNotNull() & ExpertEnum.EXPERT_BUS) == 0) {
							continue;
						}
					} else if (null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_TEC)) {
						if ((expert.getEvalBidTypeNotNull() & ExpertEnum.EXPERT_TEC) == 0) {
							continue;
						}
					} else if (null != evaluationStep.getEvalBidType() && evaluationStep.getEvalBidType().equals(EvaluationFactorEnum.EVAL_BID_DETAIL)) {
						if ((expert.getEvalBidTypeNotNull() & (ExpertEnum.EXPERT_BUS | ExpertEnum.EXPERT_TEC)) == 0) {
							continue;
						}
					}
				}else if (ObjectUtils.equals(evaluationStep.getRoleType(), EvaluationStepEnum.EVAL_GROUP)) {
					if(null == expert.getEvalGroup()){
						continue;
					}
					if(null == evalGroupStepList){
						evalGroupStepList = evaluationStepService.getEvalGroupEvalStepList(tenderProjectEntity.getId(), expert.getEvalGroup());
					}
					if (null == evalGroupStepList || !evalGroupStepList.contains(evaluationStep.getId())) {
						continue;
					}
				}
				
				returnEvaluationStepList.add(evaluationStep);
			}
		}
		return returnEvaluationStepList;
	}
}

