package com.zt.plat.module.qms.business.bus.liteflow.slot;

import java.time.LocalDateTime;
import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.zt.plat.framework.security.core.LoginUser;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessAssayTaskDataDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessBaseSampleDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessHandoverRecordSubDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleHandoverDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleHandoverDetailDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubParentSampleDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleAnalysisGroupDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleDO;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleFlowInfo;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigSampleHandoverDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigSubSampleDO;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class SampleFlowContext {
    
    /** 租户id **/
    private Long tenantId;
    
    /** 样品来源 1:主，2：子 **/
    private Integer sampleSourceType;
    
    /** 样品当前流程节点key **/
    private String currentSampleFlowKey;
    
    /** 样品id列表 **/
    private List<Long> sampleIdList;
    
    /** 样品流转列表 **/
    private List<SampleFlowInfo> sampleFlowInfoList;
    
    /**
     * 根据样品id查找样品流转信息
     * @param id
     * @return
     */
    public SampleFlowInfo getSampleFlowInfoById(Long id) {
    	SampleFlowInfo sampleFlowInfo = null;
    	if (CollUtil.isNotEmpty(this.sampleFlowInfoList)) {
			sampleFlowInfo = this.sampleFlowInfoList.stream().filter(f -> f.getId().equals(id)).findFirst().orElse(null);
		}
    	return sampleFlowInfo;
    }
    
    /** 样品交接单配置 **/
    private List<ConfigSampleHandoverDO> configSampleHandoverList;
    
    /**
     * 根据流程节点key获取交接单配置
     * @param flowNodeKey
     * @return
     */
    public ConfigSampleHandoverDO getConfigSampleHandoverByFlowNodeKey(String flowNodeKey) {
    	ConfigSampleHandoverDO configSampleHandover = null;
    	if (CollUtil.isNotEmpty(this.configSampleHandoverList)) {
			configSampleHandover = this.configSampleHandoverList.stream().filter(f -> f.getDictionarySampleFlowNodeKey().equals(flowNodeKey)).findFirst().orElse(null);
		}
    	return configSampleHandover;
    }
    
    /** 子样配置 **/
    private List<ConfigSubSampleDO> configSubSampleList;
    
    /** 根据子样配置id获取配置信息 **/
    public ConfigSubSampleDO getConfigSubSampleById(Long id) {
    	ConfigSubSampleDO configSubSample = null;
    	if (CollUtil.isNotEmpty(this.configSubSampleList)) {
			configSubSample = this.configSubSampleList.stream().filter(f -> f.getId().equals(id)).findFirst().orElse(null);
		}
    	return configSubSample;
    }
    
    /** 主样信息 **/
    private List<BusinessBaseSampleDO> businessBaseSampleList;
    
    /** 分样主样信息 **/
    private List<BusinessSubParentSampleDO> businessSubParentSampleList;
    
    /** 分样子样信息 **/
    private List<BusinessSubSampleDO> businessSubSampleList;
    
    /** 分样子样任务信息 **/
    private List<BusinessAssayTaskDataDO> businessAssayTaskDataList;
    
    /** 分样子样分析班组 **/
    private List<BusinessSubSampleAnalysisGroupDO> businessSubSampleAnalysisGroupList;
    
    /** 交接记录信息 **/
    private List<BusinessHandoverRecordSubDO> businessHandoverRecordSubList;
    
    /** 需要更新的交接记录 **/
    private List<BusinessHandoverRecordSubDO> updateBusinessHandoverRecordSubList;
    
    public BusinessHandoverRecordSubDO getBusinessHandoverRecordSubById(Long id) {
    	BusinessHandoverRecordSubDO businessHandoverRecordSub = null;
    	if (CollUtil.isNotEmpty(this.updateBusinessHandoverRecordSubList)) {
			businessHandoverRecordSub = this.updateBusinessHandoverRecordSubList.stream().filter(f -> f.getId().equals(id)).findFirst().orElse(null);
		}
    	return businessHandoverRecordSub;
    }
    
    /** 交接单主表 **/
    private BusinessSampleHandoverDO businessSampleHandover;
    
    /** 交接单明细 **/
    private List<BusinessSampleHandoverDetailDO> businessSampleHandoverDetailList;
    
    /** 当前时间 **/
    private LocalDateTime currentDateTime = LocalDateTime.now();

    /** 当前登录用户 **/
    private LoginUser loginUser;
    
    /** 当前登录人 **/
    private String loginRealname;
    
    /** 送样人 **/
    private String sendSampleOper;
    
    /** 收样人 **/
    private String receiveSampleOper;
}
