package com.gx.obe.evaluation.step.checker;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.gx.obe.business.vo.ArithmeticErrorCheckResult;
import com.gx.obe.components.core.enumeration.EngineerConstants;
import com.gx.obe.evaluation.step.entity.CacheDataClass;
import com.gx.obe.evaluation.step.inter.IChecker;
import com.gx.obe.util.utils.BigDecimalUtils;
import com.gx.obe.util.utils.DateUtils;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.web.entity.CheckResult;
import com.gx.obe.web.entity.DictionaryValue;
import com.gx.obe.web.entity.Supplier;
import com.gx.obe.web.entity.boq.BillTable;
import com.gx.obe.web.entity.boq.ConstructProject;
import com.gx.obe.web.entity.boq.MeasureTable;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.service.boq.BillTableService;
import com.gx.obe.web.service.boq.ConstructProjectService;
import com.gx.obe.web.service.boq.MeasureTableService;

/**
 * @Description: 算术性错误检查
 * @author guoyr
 */
public class ArithmeticErrorChecker extends BaseChecker implements IChecker {
	
	private ConstructProjectService constructProjectService = new ConstructProjectService();
	
	//分部分项服务
	private BillTableService billTableService = new BillTableService();
	private MeasureTableService measureTableService = new MeasureTableService();
	private List<ArithmeticErrorCheckResult> checkResultTreeList = new ArrayList<ArithmeticErrorCheckResult>();
	private List<ArithmeticErrorCheckResult> checkResultErrorList = new ArrayList<ArithmeticErrorCheckResult>();
	List<BillTable> billTableTempList;
	List<MeasureTable> measureTableTempList;
	// TODO 因已发出版本投标管家在汇总上出错，所以现在不能进行总报价检查
	public static boolean tempCheckTotalPrice = false;
	
	/**
	 * @Description:
	 * @author mazc
	 * @param tenderProject
	 * @param supplier
	 * @param evaluationStep
	 * @param dictionaryValue
	 * @param constructProject
	 */
	public void startCheck(ConstructProject constructProject) {
		
		checkResultTreeList.clear();
		checkResultErrorList.clear();
		checkResult = null;
		
		if (null == constructProject) {
			constructProject = getCacheListener().getSupplierConstructProject(tenderProject.getId(), supplier.getId());
		}
		if (null != constructProject) {
			BigDecimal totalPrice = constructProject.getTotal();// 总报价
			BigDecimal sumTotalPrice = BigDecimal.ZERO;// 汇总报价
			
			// 获得单项工程列表
			List<ConstructProject> singleConstructionList = constructProject.getChildProjectList();
			if (null != singleConstructionList) {
				for (ConstructProject singleConstruction : singleConstructionList) {
					BigDecimal singlePrice = singleConstruction.getTotal();// 单项工程报价
					sumTotalPrice = BigDecimalUtils.add(sumTotalPrice, singlePrice);
					BigDecimal sumSinglePrice = BigDecimal.ZERO;// 单项工程汇总报价
					
					ArithmeticErrorCheckResult singleResult = new ArithmeticErrorCheckResult(getEvaluationStep());
					
					// 获得单位工程
					List<ConstructProject> unitConstructionList = singleConstruction.getChildProjectList();
					if (null != unitConstructionList) {
						for (ConstructProject unitConstruction : unitConstructionList) {
							BigDecimal unitPrice = unitConstruction.getTotal();// 单位工程报价
							sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, unitPrice);
							
//							BigDecimal sumUnitPrice = getUnitConstructionSumary(unitConstruction);// 单位工程计算报价
							
							ArithmeticErrorCheckResult unitResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							unitResult.setName(unitConstruction.getProjectName());
							if (tempCheckTotalPrice) unitResult.setName(unitConstruction.getProjectName() + "合价");
							unitResult.setPrice(unitPrice);
							unitResult.setCheckType(EngineerConstants.DWGC);
//							unitResult.setCountPrice(sumUnitPrice);
							unitResult.setParent(singleResult);
//							unitResult.setOpinion("单位工程报价=分部分项报价+措施项目报价+其他项目报价+规费+税金");
//							if(!unitResult.isReasonable()){
//								checkResultErrorList.add(unitResult);
//							}
							
							ArithmeticErrorCheckResult fbfxResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							fbfxResult.setName("分部分项");
							fbfxResult.setParent(fbfxResult);
							fbfxResult.setCheckType(EngineerConstants.FBFX);
							fbfxResult.setOpinion("");
//							if(!unitResult.isReasonable()){
//								checkResultErrorList.add(unitResult);
//							}
							unitResult.addChild(fbfxResult);
							long startTime = System.currentTimeMillis(); //获取结束时间		
							LOG.debug("开始获取" + supplier.getSupplierName() + "  " + unitConstruction.getProjectName() + "分部分项清单");
							List<BillTable> billTableTempList = getCacheListener().getSupplierUnitConstructBillTableList(tenderProject.getId(), supplier.getId(), unitConstruction);
							// 检查分布分项清单
							checkBillTable(fbfxResult, unitConstruction.getId(), billTableTempList);
							LOG.debug(supplier.getSupplierName() + "  " + unitConstruction.getProjectName() + "分部分项清单  " + billTableTempList.size() + "   用时：\t" + DateUtils.timeSpan((System.currentTimeMillis() - startTime)));
							
							ArithmeticErrorCheckResult csxmResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							csxmResult.setName("单价措施");
							csxmResult.setParent(fbfxResult);
							csxmResult.setCheckType(EngineerConstants.FBFX);
							csxmResult.setOpinion("");
							unitResult.addChild(csxmResult);
							// 检查措施清单
							startTime = System.currentTimeMillis(); //获取结束时间	
							LOG.debug("开始获取" + supplier.getSupplierName() + "  " + unitConstruction.getProjectName() + "措施清单");
							List<MeasureTable> measureTableTempList = getCacheListener().getSupplierUnitConstructMeasureTableList(tenderProject.getId(), supplier.getId(), unitConstruction);
							LOG.debug(supplier.getSupplierName() + "  " + unitConstruction.getProjectName() + "措施清单  " + measureTableTempList.size() + "  用时：\t" + DateUtils.timeSpan((System.currentTimeMillis() - startTime)));
							checkMeasureTable(csxmResult, unitConstruction.getId(), measureTableTempList);
							
							singleResult.addChild(unitResult);
						}
					}
					singleResult.setPrice(singlePrice);
					singleResult.setName(singleConstruction.getProjectName() + "合价");
					singleResult.setCountPrice(sumSinglePrice);
					singleResult.setCheckType(EngineerConstants.DXGC);
					singleResult.setOpinion("单项工程报价=单位工程报价之和");
					checkResultTreeList.add(singleResult);
					if (tempCheckTotalPrice) if (!singleResult.isReasonable()) {
						checkResultErrorList.add(singleResult);
					}
				}
//mazhichao_该注释为测试用时结果，代码还需优化，优化结束后将删除
//				long endTime=System.currentTimeMillis(); //获取结束时间		
//				LOG.debug("check-： "+constructProject.getId()+"\t"+ (endTime-startTime));
//				LOG.debug("check运行时间： "+BusinessClearTenderItemComposite.formatTime(endTime-startTime));
			}
			ArithmeticErrorCheckResult totalResult = new ArithmeticErrorCheckResult(getEvaluationStep());
			totalResult.setPrice(totalPrice);
			totalResult.setName("工程总报价");
			totalResult.setOpinion("工程总报价=单项工程报价之和");
			totalResult.setCountPrice(sumTotalPrice);
			totalResult.setCheckType(EngineerConstants.GCXM);
			if (tempCheckTotalPrice) checkResultTreeList.add(0, totalResult);
			if (tempCheckTotalPrice) if (totalResult.isReasonable()) {
				checkResultErrorList.add(0, totalResult);
			}
		}
	}
	
	public void check2(TenderProjectEntity tenderProject, Supplier supplier, EvaluationStep evaluationStep, DictionaryValue dictionaryValue, ConstructProject constructProject, CacheDataClass cacheDataClass, CheckResult checkResult) {
//		super.check(tenderProject, supplier, evaluationStep, dictionaryValue,constructProject,checkResult);
		checkResultTreeList.clear();
		checkResultErrorList.clear();
		if (null == constructProject && null != checkResult) {
			this.checkResult = checkResult;
			return;
		}
//			constructProject = constructProjectService.getConstructProjectList(tenderProject.getId(), supplier.getId());		
		if (null != constructProject) {
			BigDecimal totalPrice = constructProject.getTotal();// 总报价
			BigDecimal sumTotalPrice = BigDecimal.ZERO;// 汇总报价
			
			// 获得单项工程列表
			List<ConstructProject> singleConstructionList = constructProject.getChildProjectList();
			if (null != singleConstructionList) {
//				long startTime=System.currentTimeMillis(); //获取开始时间
//				List<String> constructProjectIds = new ArrayList<String>();
//				for(ConstructProject parentConstructionList : singleConstructionList){
//					List<ConstructProject> constructionList = parentConstructionList.getChildProjectList();
//					if(constructionList.size() > 0){
//						for(ConstructProject construct : constructionList){
//							constructProjectIds.add(construct.getId());
//						}
//					}
//				}
//				constructProjectIds.clear();
//				constructProjectIds.add(supplier.getId());
				long startTime = System.currentTimeMillis(); //获取结束时间		
				billTableTempList = billTableService.getAllBillTableQDList(tenderProject.getId(), supplier.getId());
				LOG.debug(supplier.getId() + "check-： getAllBillTableQDList\t" + DateUtils.timeSpan((System.currentTimeMillis() - startTime)));
//				startTime=System.currentTimeMillis(); //获取结束时间	
//				billTableTempList = billTableService.getBillTableBTConstructionIdsList(constructProjectIds);
//				LOG.debug("check-： getBillTableBTConstructionIdsList\t"+ BusinessClearTenderItemComposite.formatTime((System.currentTimeMillis()-startTime)));
				measureTableTempList = measureTableService.getAllMeasureTableQDList(tenderProject.getId(), supplier.getId(), EngineerConstants.CSXM_DJ);
				LOG.debug(supplier.getId() + "check-： getAllMeasureTableQDList\t" + DateUtils.timeSpan((System.currentTimeMillis() - startTime)));
//				measureTableTempList = measureTableService.getAllMeasureTableQDList(tenderProject.getId(), supplier.getId(), EngineerConstants.DJCS);
				for (ConstructProject singleConstruction : singleConstructionList) {
					BigDecimal singlePrice = singleConstruction.getTotal();// 单项工程报价
					sumTotalPrice = BigDecimalUtils.add(sumTotalPrice, singlePrice);
					BigDecimal sumSinglePrice = BigDecimal.ZERO;// 单项工程汇总报价
					
					ArithmeticErrorCheckResult singleResult = new ArithmeticErrorCheckResult(getEvaluationStep());
					
					// 获得单位工程
					List<ConstructProject> unitConstructionList = singleConstruction.getChildProjectList();
					if (null != unitConstructionList) {
						for (ConstructProject unitConstruction : unitConstructionList) {
							BigDecimal unitPrice = unitConstruction.getTotal();// 单位工程报价
							sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, unitPrice);
							
							BigDecimal sumUnitPrice = getUnitConstructionSumary(unitConstruction);// 单位工程计算报价
							
							ArithmeticErrorCheckResult unitResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							unitResult.setName(unitConstruction.getProjectName() + "合价");
							unitResult.setPrice(unitPrice);
							unitResult.setCheckType(EngineerConstants.DWGC);
							unitResult.setCountPrice(sumUnitPrice);
							unitResult.setParent(singleResult);
							unitResult.setOpinion("单位工程报价=分部分项报价+措施项目报价+其他项目报价+规费+税金");
							if (!unitResult.isReasonable()) {
								checkResultErrorList.add(unitResult);
							}
							
							ArithmeticErrorCheckResult fbfxResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							fbfxResult.setName("分部分项");
							fbfxResult.setParent(unitResult);
							fbfxResult.setCheckType(EngineerConstants.FBFX);
							fbfxResult.setOpinion("");
//							if(!unitResult.isReasonable()){
//								checkResultErrorList.add(unitResult);
//							}
							unitResult.addChild(fbfxResult);
							// 检查分布分项清单
							checkBillTable(fbfxResult, unitConstruction.getId(), billTableTempList);
							
							ArithmeticErrorCheckResult csxmResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							csxmResult.setName("单价措施");
							csxmResult.setParent(unitResult);
							csxmResult.setCheckType(EngineerConstants.CSXM);
							csxmResult.setOpinion("");
							unitResult.addChild(csxmResult);
							// 检查措施清单
							checkMeasureTable(csxmResult, unitConstruction.getId(), measureTableTempList);
							
							singleResult.addChild(unitResult);
						}
					}
					singleResult.setPrice(singlePrice);
					singleResult.setName(singleConstruction.getProjectName() + "合价");
					singleResult.setCountPrice(sumSinglePrice);
					singleResult.setCheckType(EngineerConstants.DXGC);
					singleResult.setOpinion("单项工程报价=单位工程报价之和");
					checkResultTreeList.add(singleResult);
					if (!singleResult.isReasonable()) {
						checkResultErrorList.add(singleResult);
					}
				}
//mazhichao_该注释为测试用时结果，代码还需优化，优化结束后将删除
//				long endTime=System.currentTimeMillis(); //获取结束时间		
//				LOG.debug("check-： "+constructProject.getId()+"\t"+ (endTime-startTime));
//				LOG.debug("check运行时间： "+BusinessClearTenderItemComposite.formatTime(endTime-startTime));
			}
			ArithmeticErrorCheckResult totalResult = new ArithmeticErrorCheckResult(getEvaluationStep());
			totalResult.setPrice(totalPrice);
			totalResult.setName("工程总报价");
			totalResult.setOpinion("工程总报价=单项工程报价之和");
			totalResult.setCountPrice(sumTotalPrice);
			totalResult.setCheckType(EngineerConstants.GCXM);
			checkResultTreeList.add(0, totalResult);
			if (!totalResult.isReasonable()) {
				checkResultErrorList.add(0, totalResult);
			}
		}
		
	}
	
	public void check(TenderProjectEntity tenderProject, Supplier supplier, EvaluationStep evaluationStep, DictionaryValue dictionaryValue) {
		super.check(tenderProject, supplier, evaluationStep, dictionaryValue);
		checkResultTreeList.clear();
		checkResultErrorList.clear();
		// 获得工程项目
		ConstructProject constructProject = constructProjectService.getAllConstructProject(tenderProject.getId(), supplier.getId());
		if (null != constructProject) {
			BigDecimal totalPrice = constructProject.getTotal();// 总报价
			BigDecimal sumTotalPrice = getProjectSummary(constructProject);// 计算总报价
			ArithmeticErrorCheckResult totalResult = new ArithmeticErrorCheckResult(getEvaluationStep());
			totalResult.setPrice(totalPrice);
			totalResult.setName("工程总报价");
			totalResult.setOpinion("工程总报价=单项工程报价之和");
			totalResult.setCountPrice(sumTotalPrice);
			checkResultTreeList.add(totalResult);
			if (!totalResult.isReasonable()) {
				checkResultErrorList.add(totalResult);
			}
			// 获得单项工程列表
			List<ConstructProject> singleConstructionList = constructProject.getChildProjectList();
			
			if (null != singleConstructionList) {
				for (ConstructProject singleConstruction : singleConstructionList) {
					BigDecimal singlePrice = singleConstruction.getTotal();// 单项工程报价
					BigDecimal sumSinglePrice = getProjectSummary(singleConstruction);// 计算总报价
					
					ArithmeticErrorCheckResult singleResult = new ArithmeticErrorCheckResult(getEvaluationStep());
					singleResult.setPrice(singlePrice);
					singleResult.setName(singleConstruction.getProjectName() + "合价");
					singleResult.setCountPrice(sumSinglePrice);
					singleResult.setOpinion("单项工程报价=单位工程报价之和");
					checkResultTreeList.add(singleResult);
					if (!singleResult.isReasonable()) {
						checkResultErrorList.add(singleResult);
					}
					// 获得单位工程
					List<ConstructProject> unitConstructionList = singleConstruction.getChildProjectList();
					if (null != unitConstructionList) {
						for (ConstructProject unitConstruction : unitConstructionList) {
							BigDecimal unitPrice = unitConstruction.getTotal();// 单位工程报价
							BigDecimal sumUnitPrice = getUnitConstructionSumary(unitConstruction);// 单位工程计算报价
							
							ArithmeticErrorCheckResult unitResult = new ArithmeticErrorCheckResult(getEvaluationStep());
							unitResult.setName(unitConstruction.getProjectName() + "合价");
							unitResult.setPrice(unitPrice);
							unitResult.setCountPrice(sumUnitPrice);
							unitResult.setParent(singleResult);
							unitResult.setOpinion("单位工程报价=分部分项报价+措施项目报价+其他项目报价+规费+税金");
							if (!unitResult.isReasonable()) {
								checkResultErrorList.add(unitResult);
							}
							
							// 检查分布分项清单
							checkBillTable(unitResult, unitConstruction.getId());
							// 检查措施清单
							checkMeasureTable(unitResult, unitConstruction.getId());
							
							singleResult.addChild(unitResult);
						}
					}
				}
				
			}
			
		}
		
	}
	
	/**
	 * @Description: 检查分布分项清单
	 * @author mazc
	 * @param parentCheckResult
	 * @param projectId
	 * @param billTableList
	 */
	private void checkBillTable(ArithmeticErrorCheckResult parentCheckResult, String projectId, List<BillTable> billTableList) {
//		LOG.debug("数量：" + billTableList.size());
		List<BillTable> temp = new ArrayList<BillTable>();
		for (BillTable billtable : billTableList) {
			if (projectId.equals(billtable.getProjectId())) {
				BigDecimal quantity = billtable.getQuantity();
				BigDecimal price = billtable.getPrice();
				BigDecimal total = billtable.getTotal();
				BigDecimal sumTotal = BigDecimalUtils.mul(quantity, price);
				
				ArithmeticErrorCheckResult qdResult = new ArithmeticErrorCheckResult(getEvaluationStep());
				qdResult.setPrice(total);
				qdResult.setName(billtable.getBillName());
				qdResult.setCountPrice(sumTotal);
				qdResult.setParent(parentCheckResult);
				qdResult.setOpinion("清单合价=清单单价*清单工程量");
				if (!qdResult.isReasonable()) {
					checkResultErrorList.add(qdResult);
				}
				parentCheckResult.addChild(qdResult);
			} else {
				temp.add(billtable);
			}
		}
//		billTableTempList = temp;
	}
	
	/**
	 * @Description: 检查分布分项清单
	 * @author mazc
	 * @param parentCheckResult
	 * @param projectId
	 */
	private void checkMeasureTable(ArithmeticErrorCheckResult parentCheckResult, String projectId, List<MeasureTable> billTableList) {
		List<MeasureTable> temp = new ArrayList<MeasureTable>();
		for (MeasureTable measureTable : billTableList) {
			if (projectId.equals(measureTable.getProjectId())) {
				BigDecimal quantity = measureTable.getQuantity();
				BigDecimal price = measureTable.getPrice();
				BigDecimal total = measureTable.getTotal();
				BigDecimal sumTotal = BigDecimalUtils.mul(quantity, price);
				
				ArithmeticErrorCheckResult qdResult = new ArithmeticErrorCheckResult(getEvaluationStep());
				qdResult.setName(measureTable.getMeasureName());
				qdResult.setPrice(total);
				qdResult.setCountPrice(sumTotal);
				qdResult.setParent(parentCheckResult);
				qdResult.setOpinion("清单合价=清单单价*清单工程量");
				if (!qdResult.isReasonable()) {
					checkResultErrorList.add(qdResult);
				}
				parentCheckResult.addChild(qdResult);
			} else {
				temp.add(measureTable);
			}
		}
//		measureTableTempList = temp; 
	}
	
	/**
	 * @Description: 检查分布分项清单
	 * @author guoyr
	 * @param parentCheckResult
	 * @param projectId
	 */
	private void checkBillTable(ArithmeticErrorCheckResult parentCheckResult, String projectId) {
		List<BillTable> billTableList = billTableService.getBillTableQdList(projectId);
		for (BillTable qd : billTableList) {
			BigDecimal quantity = qd.getQuantity();
			BigDecimal price = qd.getPrice();
			BigDecimal total = qd.getTotal();
			BigDecimal sumTotal = BigDecimalUtils.mul(quantity, price);
			
			ArithmeticErrorCheckResult qdResult = new ArithmeticErrorCheckResult(getEvaluationStep());
			qdResult.setPrice(total);
			qdResult.setName(qd.getBillName());
			qdResult.setCountPrice(sumTotal);
			qdResult.setParent(parentCheckResult);
			qdResult.setOpinion("清单合价=清单单价*清单工程量");
			if (!qdResult.isReasonable()) {
				checkResultErrorList.add(qdResult);
			}
			parentCheckResult.addChild(qdResult);
		}
	}
	
	/**
	 * @Description: 检查分布分项清单
	 * @author guoyr
	 * @param parentCheckResult
	 * @param projectId
	 */
	private void checkMeasureTable(ArithmeticErrorCheckResult parentCheckResult, String projectId) {
		List<MeasureTable> billTableList = measureTableService.getMeasureTableQdList(projectId);
		for (MeasureTable qd : billTableList) {
			
			BigDecimal quantity = qd.getQuantity();
			BigDecimal price = qd.getPrice();
			BigDecimal total = qd.getTotal();
			BigDecimal sumTotal = BigDecimalUtils.mul(quantity, price);
			
			ArithmeticErrorCheckResult qdResult = new ArithmeticErrorCheckResult(getEvaluationStep());
			qdResult.setName(qd.getMeasureName());
			qdResult.setPrice(total);
			qdResult.setCountPrice(sumTotal);
			qdResult.setParent(parentCheckResult);
			qdResult.setOpinion("清单合价=清单单价*清单工程量");
			if (!qdResult.isReasonable()) {
				checkResultErrorList.add(qdResult);
			}
			parentCheckResult.addChild(qdResult);
		}
	}
	
	public int getErrorCount() {
		return checkResultErrorList.size();
	}
	
	@SuppressWarnings("unchecked")
	public <T> List<T> getCheckResultDetailTreeList() {
		return (List<T>) checkResultTreeList;
	}
	
	@SuppressWarnings("unchecked")
	public <T> List<T> getCheckResultErrorList() {
		return (List<T>) checkResultErrorList;
	}
	
	/**
	 * @Description: 获得工程项目或单项工程的合价
	 * @author guoyr
	 * @param constructProject
	 * @return
	 */
	private BigDecimal getProjectSummary(ConstructProject constructProject) {
		List<ConstructProject> childConstructionList = constructProject.getChildProjectList();
		BigDecimal sumSinglePrice = BigDecimal.ZERO;// 汇总报价
		if (null != childConstructionList) {
			for (ConstructProject singleConstruction : childConstructionList) {
				BigDecimal price = singleConstruction.getTotal();// 报价
				sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, price);
			}
		}
		return sumSinglePrice;
	}
	
	/**
	 * @Description: 获得工程项目或单项工程的合价
	 * @author guoyr
	 * @param unitConstruction
	 * @return
	 */
	private BigDecimal getUnitConstructionSumary(ConstructProject unitConstruction) {
		BigDecimal sumSinglePrice = BigDecimal.ZERO;// 汇总报价
		
//		 //获得分布分项报价
//		QueryWrapper billTablequeryWrapper = new QueryWrapper(BillTable.class);
//		billTablequeryWrapper.setWhereParam("projectId", unitConstruction.getId());
//		billTablequeryWrapper.setWhereParam("parentId", null, WhereParam.OP_IS);
//		BillTable billTable = billTableService.query(billTablequeryWrapper, BillTable.class); 
//		if(null != billTable){
//			sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, billTable.getTotal());
//		}
//		
//		// 获得措施报价
//		QueryWrapper measureTablequeryWrapper = new QueryWrapper(MeasureTable.class);
//		measureTablequeryWrapper.setWhereParam("projectId", unitConstruction.getId());
//		measureTablequeryWrapper.setWhereParam("parentId", null, WhereParam.OP_IS);
//		MeasureTable measureTable = measureTableService.query(measureTablequeryWrapper, MeasureTable.class); 
//		if(null != measureTable){
//			sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, measureTable.getTotal());
//		}
//		// 获得规费税金报价
//		QueryWrapper feesTaxesqueryWrapper = new QueryWrapper(FeesTaxes.class);
//		feesTaxesqueryWrapper.setWhereParam("projectId", unitConstruction.getId());
//		feesTaxesqueryWrapper.setWhereParam("parentId", null, WhereParam.OP_IS);
//		List<FeesTaxes> feesTaxesList = feesTaxesService.queryList(feesTaxesqueryWrapper, FeesTaxes.class); 
//		if(null != feesTaxesList){
//			for(FeesTaxes feesTaxes : feesTaxesList){
//				sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, feesTaxes.getTotal());
//			}
//		}
//		// 获得其他项目报价
//		QueryWrapper extraTablequeryWrapper = new QueryWrapper(ExtraTable.class);
//		extraTablequeryWrapper.setWhereParam("projectId", unitConstruction.getId());
//		extraTablequeryWrapper.setWhereParam("parentId", null, WhereParam.OP_IS);
//		ExtraTable extraTable = extraTableService.query(extraTablequeryWrapper, ExtraTable.class); 
//		if(null != extraTable){
//			sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, extraTable.getTotal());
//		}
		
//		// 获得工料机报价
//		QueryWrapper materialSummaryqueryWrapper = new QueryWrapper(MaterialSummary.class);
//		materialSummaryqueryWrapper.setWhereParam("projectId", unitConstruction.getId());
//		materialSummaryqueryWrapper.setWhereParam("parentId", null, WhereParam.OP_IS);
//		List<MaterialSummary> materialSummaryList = materialSummaryService.queryList(materialSummaryqueryWrapper, MaterialSummary.class); 
//		if(null != materialSummaryList){
//			for(MaterialSummary materialSummary : materialSummaryList){
//				sumSinglePrice = BigDecimalUtils.add(sumSinglePrice, materialSummary.getTotal());
//			}
//		}
		return sumSinglePrice;
	}
	
	public void setCheckResult(CheckResult checkResult) {
		this.checkResult = checkResult;
	}
	
	public CheckResult getCheckResult() {
		if (null != checkResult) return checkResult;
		checkResult = initCheckResult(checkResult);
		if (checkResultErrorList.size() > 0) {
			checkResult.setErrorNum(checkResultErrorList.size());
			checkResult.setAccessment(com.gx.obe.components.core.enumeration.EvaluationStepEnum.UNQUALIFIED);
			Set<String> errors = new HashSet<String>();
			for (ArithmeticErrorCheckResult checkResult : checkResultErrorList) {
				errors.add(ObjectUtils.getObjString(checkResult.getOpinion()).replace("=", "≠"));
			}
			checkResult.setCheckResult(errors.toString().substring(1, errors.toString().length() - 1) + "。");
		} else {
			checkResult.setErrorNum(0);
			checkResult.setAccessment(com.gx.obe.components.core.enumeration.EvaluationStepEnum.QUALIFIED);
			checkResult.setCheckResult("无错误。");
		}
		
		return checkResult;
	}
}
