地质所 沉降监测网建设项目
zmk
2024-05-15 9e3afc6d0fa514f986d3fea40fa23124e6fb5070
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
package com.javaweb.ehcache.controller;
 
 
import com.javaweb.common.core.controller.BaseController;
import com.javaweb.common.exception.BusinessException;
import com.javaweb.common.utils.ServletUtils;
import com.javaweb.common.utils.StringUtils;
import com.javaweb.ehcache.service.EhCacheMonitorService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
 
/**
 * Ehcache缓存监控
 * @author wujiyue
 * @date 2015/10/30
 */
@Controller
@RequestMapping("/monitor/ehcache")
public class EhCacheMonitorController extends BaseController {
    private String prefix = "monitor/ehcache";
 
    @Autowired
    EhCacheMonitorService cacheMonitorService;
    @RequestMapping(value={"","/"})
    public String index(){
        return prefix+"/list";
    }
 
    @ResponseBody
    @RequestMapping("/json/sysCacheState")
    public Object sysCacheState(){
        return cacheMonitorService.sysCacheState();
    }
    @ResponseBody
    @RequestMapping("/json/userCacheState")
    public Object userCacheState(){
        return cacheMonitorService.userCacheState();
    }
 
    @ResponseBody
    @RequestMapping("/json/getSysCacheByKey")
    public Object getSysCacheByKey(HttpServletRequest req){
        Map map= ServletUtils.getMap(req);
        return cacheMonitorService.getSysCacheByKey(map);
    }
 
    @ResponseBody
    @RequestMapping("/list")
    public Object getCacheInfo(HttpServletRequest req){
        Map map= ServletUtils.getMap(req);
        return cacheMonitorService.getCacheInfo(map);
    }
 
    /**
     * 清除缓存信息
     * @param key
     * @return
     */
    @ResponseBody
    @RequestMapping("/json/removeCacheByKey")
    public Object removeCacheByKey(String key){
        return cacheMonitorService.removeCacheByKey(key);
    }
 
    /**
     * 获得指定key的缓存信息
     * @param key
     * @return
     */
    @ResponseBody
    @RequestMapping("/json/viewCacheInfoByKey")
    public Object viewCacheInfoByKey(String key){
        return cacheMonitorService.viewCacheInfoByKey(key);
    }
 
 
    @RequestMapping("/viewCacheInfoByKey")
    public String viewCacheInfo(String key,Model model){
        if(StringUtils.isEmpty(key)){
            throw new BusinessException("参数key不能为空!");
        }
        Map<String,Object> info= cacheMonitorService.viewCacheInfoByKey(key);
        Map<String, Object> o=null;
        if(info!=null){
            List<Map<String, Object>> list=(List<Map<String, Object>>)info.get("rows");
            if(CollectionUtils.isNotEmpty(list)){
                o= list.get(0);
            }
        }
        model.addAttribute("info",o);
        return prefix+"/viewInfo";
    }
 
}