vince
2024-01-27 facc0ea3fa37091a98aa1e0a0d1081fd32fba28e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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);
        updateCache(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;
    }
 
}