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

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

import cn.hutool.core.collection.CollUtil;
import com.zt.plat.framework.security.core.LoginUser;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleAssayResultDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleEntrustDetailDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleEntrustProjectDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleEntrustRegistrationDO;
import com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSampleEntrustUnStandardProjectDO;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleFlowInfo;
import com.zt.plat.module.qms.business.config.controller.vo.MaterialAssayStandardDetailRespVO;
import com.zt.plat.module.qms.business.config.dal.dataobject.BaseSampleDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigEntrustSourceDO;
import com.zt.plat.module.qms.business.config.dal.dataobject.MaterialAssayStandardMethodDO;
import com.zt.plat.module.qms.business.dic.dal.dataobject.DictionaryProjectDO;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class SampleEntrustContext {
    
    /** 租户id **/
    private Long tenantId;
    
    /** 当前时间 **/
    private LocalDateTime currentDateTime = LocalDateTime.now();

    /** 当前登录用户 **/
    private LoginUser loginUser;
    
    /** 当前登录人 **/
    private String loginRealname;
    
    /** 中心是否收样 **/
    private Integer isReceiveSample = 0;
    
    /** 中心是否送样 **/
    private Integer isSendSample = 0;
    
    /** 样品大类 **/
    List<BaseSampleDO> baseSampleList;
    
    /** 是否使用物料分析标准 **/
    private Boolean isUseMaterialAssayStandard = true;
    
    public BaseSampleDO getBaseSampleById(Long id) {
    	BaseSampleDO baseSampleDO = null;
    	if (CollUtil.isNotEmpty(this.baseSampleList)) {
    		baseSampleDO = this.baseSampleList.stream().filter(f -> id.equals(f.getId())).findFirst().orElse(null);
		}
    	return baseSampleDO;
    }
    
    /** 委托来源 **/
    private ConfigEntrustSourceDO configEntrustSource;
    
    /** 检测项目字典列表 **/
    private List<DictionaryProjectDO> dictionaryProjectList;
    
    /**
     * 根据id获取检测项目字典
     * @param id
     * @return
     */
    public DictionaryProjectDO getDictionaryProjectById(Long id) {
    	DictionaryProjectDO dictionaryProjectDO = null;
    	if (CollUtil.isNotEmpty(this.dictionaryProjectList)) {
			dictionaryProjectDO = this.dictionaryProjectList.stream().filter(f -> id.equals(f.getId())).findFirst().orElse(null);
		}
    	return dictionaryProjectDO;
    }
    
    /** 物料检测标准检测项目列表 **/
    private List<MaterialAssayStandardDetailRespVO> materialAssayStandardDetailList;
    
    public MaterialAssayStandardDetailRespVO getMaterialAssayStandardDetailById(Long id) {
    	MaterialAssayStandardDetailRespVO materialAssayStandardDetail = null;
    	if (CollUtil.isNotEmpty(this.materialAssayStandardDetailList)) {
			materialAssayStandardDetail = this.materialAssayStandardDetailList.stream().filter(f -> id.equals(f.getId())).findFirst().orElse(null);
		}
    	return materialAssayStandardDetail;
    }
    
    /** 物料检测标准与方法列表 **/
    private List<MaterialAssayStandardMethodDO> materialAssayStandardMethodList;
    
    /** 通过检测标准项目id获取默认的检测方法  **/
    public MaterialAssayStandardMethodDO getMaterialAssayStandardMethodDefaultByMaterialAssayStandardDetailId(Long materialAssayStandardDetailId) {
    	MaterialAssayStandardMethodDO materialAssayStandardMethod = null;
    	if (CollUtil.isNotEmpty(this.materialAssayStandardMethodList)) {
			materialAssayStandardMethod = this.materialAssayStandardMethodList.stream().filter(f -> materialAssayStandardDetailId.equals(f.getMaterialAssayStandardDetailId()) && f.getIsDefault().equals(1)).findFirst().orElse(null);    		
		}
    	return materialAssayStandardMethod;
    }
    
    /** 通过检测标准项目id获取默认的检测方法列表  **/
    public List<MaterialAssayStandardMethodDO> getMaterialAssayStandardMethodDefaultByMaterialAssayStandardDetailIds(List<Long> materialAssayStandardDetailIdList) {
    	List<MaterialAssayStandardMethodDO> materialAssayStandardMethodList = null;
    	if (CollUtil.isNotEmpty(this.materialAssayStandardMethodList)) {
    		materialAssayStandardMethodList = this.materialAssayStandardMethodList.stream().filter(f -> materialAssayStandardDetailIdList.contains(f.getMaterialAssayStandardDetailId()) && f.getIsDefault().equals(1)).collect(Collectors.toList());
		}
    	return materialAssayStandardMethodList;
    }
    
    /** 委托登记单 **/
    private BusinessSampleEntrustRegistrationDO sampleEntrustRegistration;
    
    /** 委托登记样品明细 **/
    private List<BusinessSampleEntrustDetailDO> sampleEntrustDetailList;
    
    /** 委托登记样品检测项目明细 **/
    private List<BusinessSampleEntrustProjectDO> sampleEntrustProjectList;
    
    /** 委托登记样品检测项目明细(非标准) **/
    private List<BusinessSampleEntrustUnStandardProjectDO> sampleEntrustUnStandardProjectList;
    
    /** 样品委托来样品位 **/
    private List<BusinessSampleAssayResultDO> sampleAssayResultList;
    
    /** 样品流转信息列表 **/
    private List<SampleFlowInfo> sampleFlowInfoList;
}
