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
package com.yeshi.buwan.controller.admin.api;
 
import java.io.PrintWriter;
import java.util.List;
 
import javax.annotation.Resource;
 
import com.yeshi.buwan.util.EHCacheManager;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
import com.yeshi.buwan.util.SystemUtil;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.yeshi.buwan.domain.system.DetailSystemConfig;
import com.yeshi.buwan.service.imp.DetailSystemConfigService;
 
@Controller
@RequestMapping("admin/new/api/config")
public class ConfigController {
    @Resource
    private DetailSystemConfigService configService;
 
    @Resource
    private EHCacheManager ehCacheManager;
 
    @RequestMapping("configList")
    public void configList(PrintWriter out) {
 
        List<DetailSystemConfig> list = configService.getConfig(SystemUtil.getDetailSystemId(), SystemUtil.getDefaultVersion());
        JSONObject json = new JSONObject();
        json.put("code", "0");
        JSONArray listJson = new JSONArray(list);
        json.put("configList", listJson);
 
        System.out.println("Json--" + json);
        System.out.println("JsonS--" + json.toString());
 
        out.print(json);
 
        return;
    }
 
    @RequestMapping(value = "updateConfig", method = RequestMethod.POST)
    public void updateConfig(String vals, PrintWriter out) {
        List<DetailSystemConfig> list = configService.getConfig(SystemUtil.getDetailSystemId(), SystemUtil.getDefaultVersion());
 
        System.out.println("vals----" + vals);
        JSONObject json = new JSONObject(vals);
        for (DetailSystemConfig cf : list) {
            String key = cf.getKey();
            cf.setValue(json.getString(key));
//            configService.updateConfig(cf);
        }
        boolean b = configService.updateConfigList(list);
        if (b) {
            out.print("yes");
        } else {
            out.print("no");
        }
 
 
        return;
    }
 
    /**
     * 清除缓存
     *
     * @param cache
     * @param out
     */
    @RequestMapping(value = "clearCache", method = RequestMethod.POST)
    public void clearCache(String cache, PrintWriter out) {
        //清除全部缓存
        if (StringUtil.isNullOrEmpty(cache)) {
            ehCacheManager.removeAllCache();
        } else {
            ehCacheManager.clearCacheByCacheName(cache);
        }
        out.print(JsonUtil.loadTrueAdmin(""));
        return;
    }
 
}