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(Long detailSystemId, String key, String type, PrintWriter out) {
|
key = StringUtil.isNullOrEmpty(key) ? "" : key.trim();
|
List<DetailSystemConfig> list = null;
|
if ("value".equalsIgnoreCase(type)) {
|
list = configService.listConfigByValue(detailSystemId, key);
|
} else {
|
list = configService.listConfig(detailSystemId, key);
|
}
|
JSONObject json = new JSONObject();
|
json.put("code", "0");
|
JSONArray listJson = new JSONArray(list);
|
json.put("configList", listJson);
|
out.print(json);
|
return;
|
}
|
|
@RequestMapping(value = "updateConfig", method = RequestMethod.POST)
|
public void updateConfig(String id, String value, PrintWriter out) {
|
DetailSystemConfig config = configService.getConfig(Integer.parseInt(id));
|
JSONObject json = new JSONObject();
|
|
if (config == null) {
|
json.put("code", 1);
|
json.put("msg", "配置不存在");
|
} else {
|
config.setValue(value);
|
configService.saveConfig(config);
|
json.put("code", 0);
|
}
|
out.print(json);
|
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;
|
}
|
|
}
|