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 com.zt.plat.module.qms.business.bus.dal.dataobject.BusinessSubSampleDO;
import com.zt.plat.module.qms.business.bus.liteflow.slot.SampleFlowContext;
import com.zt.plat.module.qms.business.config.dal.dataobject.ConfigSubSampleDO;
import com.zt.plat.module.qms.core.code.SequenceUtil;
import com.zt.plat.module.qms.enums.QmsCommonConstant;

import jakarta.annotation.Resource;

@LiteflowComponent(id = "sampleSimpleEncryptCmp", name = "简码编密")
public class SampleSimpleEncryptCmp extends NodeComponent {
	
	@Resource
	private SequenceUtil sequenceUtil;

	@Override
	public void process() throws Exception {
		SampleFlowContext sampleFlowContext = this.getContextBean(SampleFlowContext.class);
		List<BusinessSubSampleDO> busSubCsampleList = sampleFlowContext.getBusinessSubSampleList();
		for (BusinessSubSampleDO businessSubSampleDO : busSubCsampleList) {
			ConfigSubSampleDO configSubSample = sampleFlowContext.getConfigSubSampleById(businessSubSampleDO.getConfigSubSampleId());
			String simpleCodeRule = configSubSample.getSimpleCodeRule();
			String simpleCode = sequenceUtil.genCode(simpleCodeRule);
			businessSubSampleDO.setSampleAssayCode(simpleCode);
			businessSubSampleDO.setSampleReturnCode(simpleCode);
			businessSubSampleDO.setIsGenerateReturnCode(QmsCommonConstant.YES);
		}

	}

	@Override
	public boolean isAccess() {
		SampleFlowContext sampleFlowContext = this.getContextBean(SampleFlowContext.class);
		return QmsCommonConstant.FlOW_NODE_SAMPLE_ENCRYPT.equals(sampleFlowContext.getCurrentSampleFlowKey());
	}

}
