package com.inkasso.config;

import io.seata.spring.annotation.GlobalTransactionScanner;
import io.seata.spring.boot.autoconfigure.properties.SeataProperties;
import io.seata.tm.api.DefaultGlobalTransaction;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

/**
 * @description:
 * @Author: wanglang
 * @Date: 2024/4/3 16:10
 * @Version: 1.0
 */
@Configuration
public class GlobalTransactionScannerConfig {

    private String applicationName = "factoring-trade-c";
    @Resource
    private SeataProperties seataProperties;
    @Bean
    public GlobalTransactionScanner globalTransactionScanner() {
       String txServiceGroup = this.seataProperties.getTxServiceGroup();
        if (StringUtils.isEmpty(txServiceGroup)) {
            txServiceGroup = applicationName + "-fescar-service-group";
            this.seataProperties.setTxServiceGroup(txServiceGroup);
        }

        return new GlobalTransactionScanner (applicationName, txServiceGroup);
    }
}
