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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.iplatform.base.cache;
 
import com.iplatform.base.Constants;
import com.iplatform.base.SystemGroupCache;
import com.iplatform.base.service.GroupServiceImpl;
import com.iplatform.model.po.S_group;
import com.iplatform.model.po.S_group_data;
import com.iplatform.model.vo.SystemGroupVo;
import com.walker.cache.AbstractCacheProvider;
import com.walker.cache.Cache;
import com.walker.infrastructure.utils.StringUtils;
 
import java.util.ArrayList;
import java.util.List;
 
public class LocalSystemGroupCache extends AbstractCacheProvider<SystemGroupVo> implements SystemGroupCache {
 
    @Override
    public SystemGroupVo get(int id) {
        return this.getCacheData(String.valueOf(id));
    }
 
    @Override
    public void save(SystemGroupVo category) {
        this.putCacheData(String.valueOf(category.getId()), category);
    }
 
    @Override
    public void update(SystemGroupVo category) {
        this.updateCacheData(String.valueOf(category.getId()), category);
    }
 
    @Override
    public void remove(int id) {
        this.removeCacheData(String.valueOf(id));
    }
 
    @Override
    protected int loadDataToCache(Cache cache) {
        List<S_group> hosts = this.groupService.selectAll(new S_group());
        if(!StringUtils.isEmptyList(hosts)){
            List<SystemGroupVo> groupVoList = new ArrayList<>(hosts.size());
            List<S_group_data> groupDataList = this.groupService.queryAllGroupDataList();
            for(S_group h : hosts){
                groupVoList.add(new SystemGroupVo(h));
            }
 
            if(!StringUtils.isEmptyList(groupDataList)){
                for(S_group_data data : groupDataList){
                    for(SystemGroupVo vo : groupVoList){
                        if(data.getGid().intValue() == vo.getId().intValue()){
                            vo.addGroupData(data);
                        }
                    }
                }
            }
 
            for(SystemGroupVo h : groupVoList){
                cache.put(String.valueOf(h.getId()), h);
            }
            return hosts.size();
        }
        return 0;
    }
 
    @Override
    public String getProviderName() {
        return Constants.CACHE_NAME_GROUP;
    }
 
    @Override
    public Class<?> getProviderType() {
        return SystemGroupVo.class;
    }
 
    public void setGroupService(GroupServiceImpl groupService) {
        this.groupService = groupService;
    }
 
    private GroupServiceImpl groupService;
}