shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
package com.ishop.merchant.cache;
 
import com.ishop.merchant.Constants;
import com.ishop.merchant.ExpressCache;
import com.ishop.merchant.service.ExpressServiceImpl;
import com.ishop.model.po.EbExpress;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.support.redis.cache.RedisCacheProvider;
 
public class RedisExpressCache extends RedisCacheProvider<EbExpress> implements ExpressCache {
 
    public RedisExpressCache(){
        this.setUseRedis(true);
        this.setLoadPage(false);
    }
 
    @Override
    public EbExpress get(String code) {
        if(StringUtils.isEmpty(code)){
            throw new IllegalArgumentException("请输入快递公司代码");
        }
        EbExpress express = this.getCacheData(code);
        if(express == null){
            express = this.expressService.queryOne(code);
            if(express == null){
                throw new IllegalStateException("数据库未加载到快递单位:" + code);
            }
            this.putCacheData(code, express);
        }
        return express;
    }
 
    @Override
    public void save(EbExpress category) {
        this.putCacheData(category.getCode(), category);
    }
 
    @Override
    public void update(EbExpress category) {
        this.updateCacheData(category.getCode(), category);
    }
 
    @Override
    public void remove(String code) {
        this.removeCacheData(code);
    }
 
    @Override
    public String getProviderName() {
        return Constants.CACHE_NAME_EXPRESS;
    }
 
    @Override
    public Class<?> getProviderType() {
        return EbExpress.class;
    }
 
    public void setExpressService(ExpressServiceImpl expressService) {
        this.expressService = expressService;
    }
 
    private ExpressServiceImpl expressService;
 
}