1
zj
2025-06-23 dc9bd22833255bc602dd42c7f603ecb50842ab35
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
package project.finance.data.loadcache;
 
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
 
import kernel.bo.RecordObjectMapper;
import project.finance.Finance;
import project.finance.FinanceRedisKeys;
import project.redis.RedisHandler;
 
public class FinanceLoadCacheService {
    
    private static final Logger logger = LoggerFactory.getLogger(FinanceLoadCacheService.class);
 
    private JdbcTemplate jdbcTemplate;
    private RedisHandler redisHandler;
 
    public void loadcache() {
        load();
        logger.info("完成Finance数据加载redis");
    }
 
    public void load() {
        List<Finance> list = jdbcTemplate.query("SELECT * FROM T_FINANCE", RecordObjectMapper.newInstance(Finance.class));
        Map<String, Finance> cacheMap = new ConcurrentHashMap<String, Finance>();
        for (Finance finance : list) {
            cacheMap.put(finance.getId().toString(), finance);
            redisHandler.setSync(FinanceRedisKeys.FINANCE_ID + finance.getId().toString(), finance);
        }
        redisHandler.setSync(FinanceRedisKeys.FINANCE_MAP, cacheMap);
    }
 
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
    public void setRedisHandler(RedisHandler redisHandler) {
        this.redisHandler = redisHandler;
    }
 
}