package com.gx.obe.management.action;

import java.util.List;

import org.eclipse.swt.widgets.Composite;

import com.gx.obe.action.bean.Action;
import com.gx.obe.action.listener.ActionListener;
import com.gx.obe.action.utils.ActionUtil;
import com.gx.obe.business.enumeration.MenuEnum;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.EvaluationStepEnum;
import com.gx.obe.evaluation.step.listener.ExpertEvaluationListener;
import com.gx.obe.evaluation.step.resutl.action.BusinessEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.BusinessVetoEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.ClearTenderEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.ComplianceEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.CreditEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.EditPriceResultAction;
import com.gx.obe.evaluation.step.resutl.action.ExpertSignResutlAction;
import com.gx.obe.evaluation.step.resutl.action.FeatureCodeCheckResultAction;
import com.gx.obe.evaluation.step.resutl.action.LimitPriceEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.MultiWheelPriceEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.PreEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.PriceEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.RecommendRankEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.RecommonedEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.ScoreEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.TotalPriceEvaluationResultAction;
import com.gx.obe.evaluation.step.resutl.action.VetoBidEvaluationResultAction;
import com.gx.obe.evaluation.step.review.action.AbandonEvalutionAction;
import com.gx.obe.evaluation.step.review.action.BusinessEvaluationAction;
import com.gx.obe.evaluation.step.review.action.CreditEvaluationAction;
import com.gx.obe.evaluation.step.review.action.EditPriceAction;
import com.gx.obe.evaluation.step.review.action.LimitPriceEvaluationAction;
import com.gx.obe.evaluation.step.review.action.MultiWheelPriceEvaluationAction;
import com.gx.obe.evaluation.step.review.action.PriceEvaluationAction;
import com.gx.obe.evaluation.step.review.action.RecommonedEvaluationAction;
import com.gx.obe.evaluation.step.review.action.TianYanCheckAction;
import com.gx.obe.evaluation.step.review.action.TianYanCheckEvaluationAction;
import com.gx.obe.evaluation.step.review.action.TianYanCheckResultAction;
import com.gx.obe.evaluation.step.review.action.TotalPriceEvaluationAction;
import com.gx.obe.evaluation.step.review.action.VetoBidEvaluationAction;
import com.gx.obe.web.entity.auth.Menu;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.MenuService;
import com.gx.obe.web.service.TenderProjectService;
import com.gx.obe.web.service.evaluation.EvaluationStepService;

/**
 * @Description: 评标结果操作公共action
 * @author guoyr
 */
public class LoadEvaluationResultCommonAction extends Action {
	private Action action;
	private ActionListener listener;
	private EvaluationStep evaluationStep;
	private Menu menu;
	private TenderProjectService tenderProjectService ;
	private MenuService menuService ;
	private EvaluationStepService evaluationStepService = new EvaluationStepService();

	@Override
	public void run() {
		listener = this.getListener();
		if(null == menuService){
			menuService = new MenuService();
		}
		menu = menuService.getMenutByMenuCode(MenuEnum.EVALUATION_RESULT);
		if(null == menu) {
			menu = this.getMenu();
		}
		evaluationStep = (EvaluationStep) this.getData("evaluationStep");
		evaluationStep = evaluationStepService.getById(evaluationStep.getId());
//		TenderProjectEntity tenderProjectEntity = (TenderProjectEntity) this.getData("tenderProjectEntity");
		TenderProjectEntity tenderProjectEntity = this.getTenderProject();
		TenderProjectRuleEntity tenderProjectRuleEntity = this.getTenderProjectRule();
		String result = (String)this.getData("result");
		if(null == tenderProjectService){
			tenderProjectService = new TenderProjectService();
		}
		tenderProjectEntity = tenderProjectService.getById(tenderProjectEntity.getId() );
		ExpertEvaluationListener expertEvaluationListener = (ExpertEvaluationListener) this.getData("expertEvaluationListener");
		Composite parentComposite = this.getListener().getParentComposite();
		parentComposite.setData("tenderProjectEntity", tenderProjectEntity);
		parentComposite.setData("tenderProjectRuleEntity", tenderProjectRuleEntity);
		parentComposite.setData("evaluationStep", evaluationStep);
		if (null != evaluationStep) {
			boolean isComplate = CommonEnum.COMPLETE.equals(evaluationStep.getStepStatus());
			// 如果是只查看结果界面
			if(null != result){
				isComplate = true;
			}
			boolean isOperatorRole = EvaluationStepEnum.OPERATOR.equals(evaluationStep.getRoleType());
			if (evaluationStep.getStepType().equals(EvaluationStepEnum.SIGIN)) {
				action = (Action) ActionUtil.getAction(ExpertSignResutlAction.class.getName());
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.FEATURE_CHECK)) {
				action = (Action) ActionUtil.getAction(FeatureCodeCheckResultAction.class.getName());
				action.setData("expertEvaluationListener", expertEvaluationListener);
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.ASSOCIATION_QUERY)) {
				action = (Action) ActionUtil.getAction(TianYanCheckResultAction.class.getName());
				action.setData("expertEvaluationListener", expertEvaluationListener);
//				if (isOperatorRole && !isComplate) {
//					action = (Action) ActionUtil.getAction(TianYanCheckAction.class.getName());
//					action.setData("hideLeft", true);
//					action.setData("expertEvaluationListener", expertEvaluationListener);
//					action.setData("TianyanCheck", "true");
//				} else {
//					action = (Action) ActionUtil.getAction(TianYanCheckResultAction.class.getName());
//				}
			}else if (evaluationStep.getStepType().equals(EvaluationStepEnum.CLEAN_TENDER)) {
				action = (Action) ActionUtil.getAction(ClearTenderEvaluationResultAction.class.getName());
				action.setData("expertEvaluationListener", expertEvaluationListener);
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.COMPLIANCE)) {
				action = (Action) ActionUtil.getAction(ComplianceEvaluationResultAction.class.getName());
				action.setData("expertEvaluationListener", expertEvaluationListener);
			} else if (EvaluationStepEnum.DETAIL.equals(evaluationStep.getStepType()) || EvaluationStepEnum.FIXED_FACTOR.equals(evaluationStep.getStepType())) {
				if(null != evaluationStep.getSummaryType() && evaluationStep.getSummaryType().equals(EvaluationStepEnum.SUMMARY_SCORE_BY_QUALIFIED)){
					action = (Action) ActionUtil.getAction(ComplianceEvaluationResultAction.class.getName());
				}else {
					action = (Action) ActionUtil.getAction(ScoreEvaluationResultAction.class.getName());
				}
				action.setData("expertEvaluationListener", expertEvaluationListener);
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.MULTI_ROUNDS_PRICE)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(MultiWheelPriceEvaluationAction.class.getName());
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(MultiWheelPriceEvaluationResultAction.class.getName());
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.TOTAL_PRICE)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(TotalPriceEvaluationAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(TotalPriceEvaluationResultAction.class.getName());
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.EDIT_PRICE)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(EditPriceAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(EditPriceResultAction.class.getName());
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.PRICE)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(PriceEvaluationAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(PriceEvaluationResultAction.class.getName());
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.BID_PRICE_LIMIT)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(LimitPriceEvaluationAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(LimitPriceEvaluationResultAction.class.getName());
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.RECOMMONED_RANK)) {
				action = (Action) ActionUtil.getAction(RecommendRankEvaluationResultAction.class.getName());
				action.setData("expertEvaluationListener", expertEvaluationListener);
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.VETO_BID)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(VetoBidEvaluationAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(VetoBidEvaluationResultAction.class.getName());
				}
			}else if (evaluationStep.getStepType().equals(EvaluationStepEnum.CREDIT)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(CreditEvaluationAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(CreditEvaluationResultAction.class.getName());
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.RECOMMONED)) {
				if (isOperatorRole && !isComplate) {
					action = (Action) ActionUtil.getAction(RecommonedEvaluationAction.class.getName());
					action.setData("hideLeft", true);
					action.setData("expertEvaluationListener", expertEvaluationListener);
				} else {
					action = (Action) ActionUtil.getAction(RecommonedEvaluationResultAction.class.getName());
					List<EvaluationStep> recommonedRankList = evaluationStepService.getEvaluationStepListByType(tenderProjectEntity.getId(), EvaluationStepEnum.RECOMMONED_RANK);
					if (null != recommonedRankList && recommonedRankList.size() > 0) {
						action.setData(EvaluationStepEnum.RECOMMONED_RANK, recommonedRankList.get(0));
					}
				}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.BUSINESS_VETO)) {
                action = (Action) ActionUtil.getAction(BusinessVetoEvaluationResultAction.class.getName());
            } else if (evaluationStep.getStepType().equals(EvaluationStepEnum.BILL)) {
            	if (isOperatorRole && !isComplate) {
            		action = (Action) ActionUtil.getAction(BusinessEvaluationAction.class.getName());
            		action.setData("hideLeft", true);
            		action.setData("expertEvaluationListener", expertEvaluationListener);
            	}else{
            		action = (Action) ActionUtil.getAction(BusinessEvaluationResultAction.class.getName());
            	}
			} else if (evaluationStep.getStepType().equals(EvaluationStepEnum.WASTE_BID)) {
				action = (Action) ActionUtil.getAction(AbandonEvalutionAction.class.getName());
				action.setData("hideLeft", true);
				action.setData("result", "result");
			}else if (evaluationStep.getStepType().equals(EvaluationStepEnum.PRE_EVALUATION)) {
				action = (Action) ActionUtil.getAction(PreEvaluationResultAction.class.getName());
			}
		}
		if (null != action) {
			if (null != evaluationStep.getRoleType() && evaluationStep.getRoleType().equals(EvaluationStepEnum.OPERATOR)){
				action.setData(Constants.OPERATOR_USERID, Constants.USER.getId());
			}
			action.setData("evaluationStep", evaluationStep);
			action.setMenu(menu);
			action.setTenderProject(tenderProjectEntity);
			action.setTenderProjectRule(tenderProjectRuleEntity);
			action.setEvaluationStep(evaluationStep);
			action.addActionListener(listener);
			action.setMenu(this.getMenu());
			action.run();
		}
	}
}
