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

import java.util.List;

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

import cn.hutool.core.collection.CollUtil;
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.dal.mapper.BusinessAssayTaskDataMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessBaseSampleMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessHandoverRecordSubMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSampleHandoverDetailMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSampleHandoverMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSubParentSampleMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSubSampleAnalysisGroupMapper;
import com.zt.plat.module.qms.business.bus.dal.mapper.BusinessSubSampleMapper;
import com.zt.plat.module.qms.business.bus.liteflow.slot.SampleFlowContext;
import jakarta.annotation.Resource;

@LiteflowComponent(id = "sampleDataSaveOrUpdateCmp", name = "样品相关数据保存或更新")
public class SampleDataSaveOrUpdateCmp extends NodeComponent {
	
	@Resource
	private BusinessBaseSampleMapper businessBaseSampleMapper;
	
	@Resource
	private BusinessSubParentSampleMapper businessSubParentSampleMapper;
	
	@Resource
	private BusinessSubSampleMapper businessSubSampleMapper;
	
	@Resource
	private BusinessAssayTaskDataMapper businessAssayTaskDataMapper;
	
	@Resource
	private BusinessSubSampleAnalysisGroupMapper businessSubSampleAnalysisGroupMapper;
	
	@Resource
	private BusinessHandoverRecordSubMapper businessHandoverRecordSubMapper;
	
	@Resource
	private BusinessSampleHandoverMapper businessSampleHandoverMapper;
	
	@Resource
	private BusinessSampleHandoverDetailMapper businessSampleHandoverDetailMapper;

	@Override
	public void process() throws Exception {
		SampleFlowContext sampleFlowContext = this.getContextBean(SampleFlowContext.class);
		//主样
		List<BusinessBaseSampleDO> businessBaseSampleList = sampleFlowContext.getBusinessBaseSampleList();
		if (CollUtil.isNotEmpty(businessBaseSampleList)) {
			businessBaseSampleMapper.updateBatch(businessBaseSampleList);
		}
		//分样
		List<BusinessSubParentSampleDO> busSubPsampleList = sampleFlowContext.getBusinessSubParentSampleList();
		if (CollUtil.isNotEmpty(busSubPsampleList)) {
			businessSubParentSampleMapper.updateBatch(busSubPsampleList);
		}
		//子样
		List<BusinessSubSampleDO> busSubCsampleList = sampleFlowContext.getBusinessSubSampleList();
		if (CollUtil.isNotEmpty(busSubCsampleList)) {
			businessSubSampleMapper.updateBatch(busSubCsampleList);
		}
		//子样任务
		List<BusinessAssayTaskDataDO> businessAssayTaskDataList = sampleFlowContext.getBusinessAssayTaskDataList();
		if (CollUtil.isNotEmpty(businessAssayTaskDataList)) {
			businessAssayTaskDataMapper.updateBatch(businessAssayTaskDataList);
		}
		//子样分析班组
		List<BusinessSubSampleAnalysisGroupDO> businessSubSampleAnalysisGroupList = sampleFlowContext.getBusinessSubSampleAnalysisGroupList();
		if (CollUtil.isNotEmpty(businessSubSampleAnalysisGroupList)) {
			businessSubSampleAnalysisGroupMapper.updateBatch(businessSubSampleAnalysisGroupList);
		}
		//交接记录
		List<BusinessHandoverRecordSubDO> busHandoverRecordSubList = sampleFlowContext.getBusinessHandoverRecordSubList();
		if (CollUtil.isNotEmpty(busHandoverRecordSubList)) {
			businessHandoverRecordSubMapper.insertBatch(busHandoverRecordSubList);
		}
		List<BusinessHandoverRecordSubDO> updateBusinessHandoverRecordSubList = sampleFlowContext.getUpdateBusinessHandoverRecordSubList();
		if (CollUtil.isNotEmpty(updateBusinessHandoverRecordSubList)) {
			businessHandoverRecordSubMapper.updateBatch(updateBusinessHandoverRecordSubList);
		}
		//交接记录单
		BusinessSampleHandoverDO businessSampleHandover = sampleFlowContext.getBusinessSampleHandover();
		if (businessSampleHandover != null) {
			businessSampleHandoverMapper.insert(businessSampleHandover);
		}
		//交接记录单明细
		List<BusinessSampleHandoverDetailDO> businessSampleHandoverDetailList = sampleFlowContext.getBusinessSampleHandoverDetailList();
		if (CollUtil.isNotEmpty(businessSampleHandoverDetailList)) {
			businessSampleHandoverDetailMapper.insertBatch(businessSampleHandoverDetailList);
		}
	}

}
