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

import org.eclipse.swt.SWT;
import org.eclipse.swt.core.MessageDialog;

import com.gx.obe.action.bean.EAction;
import com.gx.obe.components.core.Constants;
import com.gx.obe.components.core.enumeration.CommonEnum;
import com.gx.obe.components.core.enumeration.ExpertEnum;
import com.gx.obe.evaluation.step.dialog.ViewBidPriceResultDialog;
import com.gx.obe.util.utils.ObjectUtils;
import com.gx.obe.web.entity.evaluation.EvaluationStep;
import com.gx.obe.web.entity.expert.Expert;
import com.gx.obe.web.entity.tender.TenderProjectEntity;
import com.gx.obe.web.entity.tender.TenderProjectRuleEntity;
import com.gx.obe.web.service.ProjectRuleService;

/**
 * @Description: 查看投标报价及与价格得分事件
 * @author guoyr
 */
public class ViewBidPriceEvaluationResultAction extends EAction {
	public void run(){
		TenderProjectEntity tenderProjectEntity = this.getTenderProject();
		EvaluationStep evaluationStep = (EvaluationStep)this.getData("evaluationStep");
		Expert CURRENT_EXPERT = (Expert) this.getData(Constants.CUR_EXPERT);
		if(null != tenderProjectEntity){
			if(null != CURRENT_EXPERT){
				if(ObjectUtils.equals(CURRENT_EXPERT.getSignType(), ExpertEnum.AVOID)){
					MessageDialog.openWarning(this.getParent().getShell(), "您已经回避！");
					return;
				}else if(!ObjectUtils.equals(CURRENT_EXPERT.getSignType(), ExpertEnum.SIGN)){
					
					MessageDialog.openWarning(this.getParent().getShell(), "请您先签到！");
					return;
				}
			}
			
//			QueryWrapper queryWrapper = new QueryWrapper(TenderProjectRuleEntity.class);
//			queryWrapper.setQueryParm("viewBidPrice");
//			queryWrapper.setQueryParm("viewPriceScore");
//			queryWrapper.setQueryParm("priceUint");
//			queryWrapper.setWhereParam("tenderId", tenderProjectEntity.getId());
			ProjectRuleService projectRuleService = new ProjectRuleService();;
			TenderProjectRuleEntity tenderProjectRuleEntity = projectRuleService.getProjectRule(tenderProjectEntity.getId());
			if(null == tenderProjectRuleEntity){
				tenderProjectRuleEntity = new TenderProjectRuleEntity();
			}
			boolean viewBidPrice = false;
			boolean viewPriceScore = false;
			
			// 如果是经济标专家，或有查看价格的权限
			if ((CURRENT_EXPERT.getEvalBidTypeNotNull() & ExpertEnum.EXPERT_PRICE) != 0 || ObjectUtils.equals(tenderProjectRuleEntity.getViewBidPrice() , CommonEnum.YES)) {
				viewBidPrice = true;
			}
			if(ObjectUtils.equals(tenderProjectRuleEntity.getViewPriceScore() , CommonEnum.YES)){
				viewPriceScore = true;
			}
			// 如果有权限查看价格得分
			if(!viewBidPrice && !viewPriceScore){
				MessageDialog.openWarning(this.getParent().getShell(), "您无查看报价（报价得分）的权限！");
				return ;
			}
			ViewBidPriceResultDialog dialog = new ViewBidPriceResultDialog(this.getParent().getShell(), tenderProjectEntity, tenderProjectRuleEntity, evaluationStep);
			dialog.setOperator(SWT.MAX | SWT.CLOSE);
			dialog.open();
		
		}
	}
}
