package com.sunxung.factoring.component.util.fdd;


import cn.hutool.core.convert.impl.UUIDConverter;
import cn.hutool.core.lang.UUID;
import com.fasterxml.uuid.UUIDGenerator;
import com.sunxung.factoring.component.cache.CacheKeyGenerator;
import com.sunxung.factoring.component.cache.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * FDD transactionId生成器
 * @author daxian
 */
@Component
public class TransactionIdCache {

    @Autowired
    private RedisCache redisCache;

    /**
     *
     * @param obj
     * @return
     */
    public void saveObjBuildTransactionId(String transactionId , Object obj){
        String key = CacheKeyGenerator.generateCacheKeyFromString(TransactionIdCache.class,transactionId);
        redisCache.set(key,60*60*24*30,obj);
    }

    public Object getObjByTransactionId(String transactionId){
        String key = CacheKeyGenerator.generateCacheKeyFromString(TransactionIdCache.class,transactionId);
        return redisCache.get(key);
    }

    public void removeObjByTransactionId(String transactionId){
        String key = CacheKeyGenerator.generateCacheKeyFromString(TransactionIdCache.class,transactionId);
        redisCache.remove(key);
    }

    public void expireObjByTransactionId(String transactionId){
        String key = CacheKeyGenerator.generateCacheKeyFromString(TransactionIdCache.class,transactionId);
        Object obj = redisCache.get(key);
        if(obj!=null){
            redisCache.set(key,60*60*24*30,obj);
        }

    }

}
