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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.iplatform.api;
 
import com.iplatform.base.SystemController;
import com.iplatform.base.cache.DictCacheProvider;
import com.iplatform.model.po.S_dict_data;
import com.iplatform.model.po.S_host;
import com.walker.cache.CacheProvider;
import com.walker.cache.SimpleCacheManager;
import com.walker.cache.tree.CacheTreeNode;
import com.walker.web.ResponseValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Collection;
import java.util.List;
 
@RestController
@RequestMapping("/test/cache")
public class TestCacheApi extends SystemController {
 
//    @RequestMapping("/city_cache")
//    public ResponseValue testCityCache(){
//        CityCacheProvider cityCacheProvider = BeanContextAware.getBeanByType(CityCacheProvider.class);
//        List<CityTreeVo> list = cityCacheProvider.getTree();
//        if(!StringUtils.isEmptyList(list)){
//            logger.info("城市区域树根(省份)节点数量:" + list.size());
//            for(CityTreeVo vo : list){
//                logger.info(".......... " + vo.getRegionName() + ": children = " + vo.getChild().size());
//            }
//        }
//        return ResponseValue.success();
//    }
//
//    @RequestMapping("/product_attr_del")
//    public ResponseValue testRemoveProductAttr(String key, String attrId){
//        ProductAttrServiceImpl productAttrService = BeanContextAware.getBeanByType(ProductAttrServiceImpl.class);
//        ProductAttrCache cache = BeanContextAware.getBeanByType(ProductAttrCache.class);
////        String[] typeAndProductId = ProductAttrUtils.splitTypeAndProductId(key);
//        EbProductAttr productAttr = productAttrService.get(new EbProductAttr(Integer.parseInt(attrId)));
//        cache.removeList(key, productAttr);
//        logger.info("删除一个缓存,key={}, list={}", key, cache.getList(key));
//        return ResponseValue.success();
//    }
//
//    @RequestMapping("/product_attr")
//    public ResponseValue testProductAttrCache(String key){
//        ProductAttrCache cache = BeanContextAware.getBeanByType(ProductAttrCache.class);
//        List<EbProductAttr> list = cache.getList(key);
//        logger.info("获取一次缓存,key = {}, list = {}", key, list);
//        return ResponseValue.success();
//    }
 
    @RequestMapping("/access")
    public ResponseValue testPermitNotLoginAccess(){
        return ResponseValue.success();
    }
 
    @RequestMapping("/dict_tree")
    public ResponseValue acquireDictTree(){
        DictCacheProvider dictCacheProvider = (DictCacheProvider)SimpleCacheManager.getCacheProvider(S_dict_data.class);
        List<CacheTreeNode> list01 = dictCacheProvider.getCodeList(new String[]{"101001001", "101002"});
        for(CacheTreeNode node : list01){
            logger.debug(node.getText());
        }
        logger.info("-----------------------------");
 
        // 返回代码字典下第一级集合
        List<S_dict_data> list02 = dictCacheProvider.getRootChildrenOneLevelList("101");
        for(S_dict_data dict_data : list02){
            logger.debug(dict_data.getDict_label());
        }
        logger.info("-----------------------------");
 
        // 返回 题库一级(历史) 下面所有代码树
        List<CacheTreeNode> list03 = dictCacheProvider.getCodeChildrenTreeList("101002");
        for(CacheTreeNode node : list03){
            this.printRecursion(node);
        }
        logger.info("-----------------------------");
        return ResponseValue.success();
    }
 
    private String printRecursion(CacheTreeNode node){
        logger.debug(node.getText());
        Collection<CacheTreeNode> child = node.getChildren();
        if(child == null || child.size() == 0){
            return null;
        }
        String success = null;
        for(CacheTreeNode n : child){
            success = printRecursion(n);
            if(success == null){
                continue;
            }
        }
        return null;
    }
 
    /**
     *
     * @param id 主键1可以测试
     * @return
     */
    @RequestMapping("/get_host")
    public String testGetCacheHost(String id){
        S_host host = this.getHostCacheProvider().getCacheData(id);
        if(host == null){
            return "没找到缓存host: " + id;
        } else {
            return "找到缓存host: " + host;
        }
    }
 
    protected CacheProvider<S_host> getHostCacheProvider(){
        return SimpleCacheManager.getCacheProvider(S_host.class);
    }
}