package com.zt.plat.module.qms.business.bus.liteflow.sample.taskassign;

import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.NodeComponent;

import com.zt.plat.framework.security.core.LoginUser;
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
import com.zt.plat.framework.tenant.core.context.TenantContextHolder;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleTaskAssignManualParam;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleTaskAssignManualTypeParam;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleTaskAssignMethodParam;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleTaskAssignProjectMethodParam;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleTaskAssignProjectNoMethodParam;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleTaskAssignSampleParam;
import com.zt.plat.module.qms.business.bus.liteflow.slot.SampleTaskAssignContext;
import com.zt.plat.module.qms.business.bus.liteflow.slot.SampleTaskAssignTypeEnum;

@LiteflowComponent(id = "sampleTaskAssignContextInitCmp", name = "任务分配上下文初始化")
public class SampleTaskAssignContextInitCmp extends NodeComponent {
	
	@Override
	public void process() throws Exception {
		//租户id
		Long tenantId = TenantContextHolder.getRequiredTenantId();
		
		//当前登录用户
		LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
		
		//当前登录用户昵称
		String nickName = SecurityFrameworkUtils.getLoginUserNickname();
		
		SampleTaskAssignContext sampleTaskAssignContext = this.getContextBean(SampleTaskAssignContext.class);
		sampleTaskAssignContext.setTenantId(tenantId);
		sampleTaskAssignContext.setLoginUser(loginUser);
		sampleTaskAssignContext.setLoginRealname(nickName);
		
		if (this.getRequestData() instanceof SampleTaskAssignMethodParam) {
			SampleTaskAssignMethodParam sampleTaskAssignMethodParam = this.getRequestData();
			sampleTaskAssignContext.setSampleTaskAssignType(SampleTaskAssignTypeEnum.ASSAY_METHOD);
			sampleTaskAssignContext.setAssignConfigAssayMethodId(sampleTaskAssignMethodParam.getConfigAssayMethodId());
			sampleTaskAssignContext.setAssignAssayUserList(sampleTaskAssignMethodParam.getAssignAssayUserList());
		}
		
		if (this.getRequestData() instanceof SampleTaskAssignSampleParam) {
			SampleTaskAssignSampleParam sampleTaskAssignSampleParam = this.getRequestData();
			sampleTaskAssignContext.setSampleTaskAssignType(SampleTaskAssignTypeEnum.SAMPLE);
			sampleTaskAssignContext.setAssignAssayUser(sampleTaskAssignSampleParam.getAssignAssayUser());
			sampleTaskAssignContext.setAssignSampleIdList(sampleTaskAssignSampleParam.getAssignSampleIdList());			
		}
		
		if (this.getRequestData() instanceof SampleTaskAssignManualParam) {
			SampleTaskAssignManualParam sampleTaskAssignManualParam = this.getRequestData();
			sampleTaskAssignContext.setSampleTaskAssignType(SampleTaskAssignTypeEnum.MANUAL);
			sampleTaskAssignContext.setAssignAssayUser(sampleTaskAssignManualParam.getAssignAssayUser());
			sampleTaskAssignContext.setAssayTaskDataIdList(sampleTaskAssignManualParam.getAssayTaskDataIdList());			
			
		}
		
		if (this.getRequestData() instanceof SampleTaskAssignManualTypeParam) {
			SampleTaskAssignManualTypeParam sampleTaskAssignManualParam = this.getRequestData();
			sampleTaskAssignContext.setSampleTaskAssignType(SampleTaskAssignTypeEnum.MANUAL_TYPE);
			sampleTaskAssignContext.setAssignAssayUserList(sampleTaskAssignManualParam.getAssignAssayUserList());
			sampleTaskAssignContext.setAssayTaskDataIdList(sampleTaskAssignManualParam.getAssayTaskDataIdList());
		}
		
		if (this.getRequestData() instanceof SampleTaskAssignProjectMethodParam) {
			SampleTaskAssignProjectMethodParam sampleTaskAssignProjectMethodParam = this.getRequestData();
			sampleTaskAssignContext.setSampleTaskAssignType(SampleTaskAssignTypeEnum.PROJECT_METHOD);
			sampleTaskAssignContext.setAssignConfigAssayMethodId(sampleTaskAssignProjectMethodParam.getConfigAssayMethodId());
			sampleTaskAssignContext.setAssayType(sampleTaskAssignProjectMethodParam.getAssayType());
			sampleTaskAssignContext.setAssayTaskCount(sampleTaskAssignProjectMethodParam.getAssayTaskCount());
			sampleTaskAssignContext.setAssignAssayUserList(sampleTaskAssignProjectMethodParam.getAssignAssayUserList());
			sampleTaskAssignContext.setAssayProjectDataIdList(sampleTaskAssignProjectMethodParam.getAssayProjectDataIdList());
		}
		
		if (this.getRequestData() instanceof SampleTaskAssignProjectNoMethodParam) {
			SampleTaskAssignProjectNoMethodParam sampleTaskAssignProjectNoMethodParam = this.getRequestData();
			sampleTaskAssignContext.setSampleTaskAssignType(SampleTaskAssignTypeEnum.PROJECT_NO_METHOD);
			sampleTaskAssignContext.setAssignConfigAssayMethodId(sampleTaskAssignProjectNoMethodParam.getConfigAssayMethodId());
			sampleTaskAssignContext.setAssayType(sampleTaskAssignProjectNoMethodParam.getAssayType());
			sampleTaskAssignContext.setAssayTaskCount(sampleTaskAssignProjectNoMethodParam.getAssayTaskCount());
			sampleTaskAssignContext.setAssignAssayUserList(sampleTaskAssignProjectNoMethodParam.getAssignAssayUserList());
			sampleTaskAssignContext.setSampleEntrustUnStandardProjectIdList(sampleTaskAssignProjectNoMethodParam.getSampleEntrustUnStandardProjectIdList());
		}

	}

}
