package com.fzzy.gateway.service;
|
|
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;
|
|
|
/**
|
* gatewayConfService#listAll
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<GatewayConf> listAll() {
|
|
List<GatewayConf> list = gatewayConfRep.findAll();
|
|
return list;
|
}
|
|
/**
|
* gatewayConfService#listAll#updateSave
|
*
|
* @param entity
|
*/
|
@DataResolver
|
public void updateSave(GatewayConf entity) {
|
GatewayConf data = new GatewayConf();
|
BeanUtils.copyProperties(entity, data);
|
gatewayConfRep.save(data);
|
}
|
|
/**
|
* gatewayConfService#delData
|
*
|
* @param data
|
*/
|
@Expose
|
public String delData(GatewayConf data) {
|
|
GatewayConf data2 = new GatewayConf();
|
BeanUtils.copyProperties(data, data2);
|
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;
|
}
|
|
}
|