jiazx0107@163.com
2023-12-24 8efb5a8cd2c8a6b40e58f4f3fb851d54cf415af9
src/main/java/com/fzzy/gateway/service/GatewayConfService.java
@@ -3,19 +3,27 @@
import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.fzzy.api.utils.RedisConst;
import com.fzzy.api.utils.RedisUtil;
import com.fzzy.gateway.entity.GatewayConf;
import com.fzzy.gateway.service.repository.GatewayConfRep;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@Slf4j
@Component
public class GatewayConfService {
    @Resource
    private GatewayConfRep gatewayConfRep;
    @Resource
    private RedisUtil redisUtil;
    /**
@@ -41,6 +49,7 @@
        GatewayConf data = new GatewayConf();
        BeanUtils.copyProperties(entity, data);
        gatewayConfRep.save(data);
        updateCache(data);
    }
    /**
@@ -56,4 +65,31 @@
        gatewayConfRep.delete(data2);
        return null;
    }
    public void updateCache(GatewayConf conf) {
        String key = RedisConst.buildKey(RedisConst.KYE_CONF_GATEWAY, conf.getKqdm());
        redisUtil.set(key, conf);
    }
    public GatewayConf getCacheConf(String kqdm) {
        try {
            String key = RedisConst.buildKey(RedisConst.KYE_CONF_GATEWAY, kqdm);
            return (GatewayConf) redisUtil.get(key);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            return null;
        }
    }
    public List<GatewayConf> getCacheConfList() {
        String tag = RedisConst.buildKey(RedisConst.KYE_CONF_GATEWAY);
        Set<String> keys = redisUtil.keys(tag);
        List<GatewayConf> result = new ArrayList<>();
        for (String key : keys) {
            result.add((GatewayConf) redisUtil.get(key));
        }
        return result;
    }
}