package com.zt.plat.module.qms.business.bus.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;

import com.zt.plat.framework.common.exception.ServiceException;
import com.zt.plat.framework.tenant.core.context.TenantContextHolder;
import com.zt.plat.module.qms.business.bus.liteflow.param.SampleFlowParam;
import com.zt.plat.module.qms.business.bus.liteflow.slot.SampleFlowContext;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class SampleFlowServiceImpl implements SampleFlowService {

    @Resource
    private FlowExecutor flowExecutor;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public LiteflowResponse sampleFlow(SampleFlowParam sampleFlowParam) {
    	Long tenantId = TenantContextHolder.getRequiredTenantId();
		LiteflowResponse response = flowExecutor.execute2Resp("sampleFlowChain" + tenantId, sampleFlowParam, SampleFlowContext.class);
	    if (!response.isSuccess()){
	    	log.error("样品流转失败", response.getCause());
            throw new ServiceException(1_032_100_000, response.getCause().getMessage());
        }
	    return response;
	}

}
