package com.yeshi.fanli.controller.admin;
|
|
import java.io.PrintWriter;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import com.yeshi.fanli.entity.system.System;
|
import com.yeshi.fanli.entity.system.SystemConfig;
|
import com.yeshi.fanli.exception.NotExistObjectException;
|
import com.yeshi.fanli.service.inter.config.SystemConfigService;
|
import com.yeshi.fanli.service.inter.config.SystemService;
|
import com.yeshi.fanli.tag.PageEntity;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.Utils;
|
import org.yeshi.utils.JsonUtil;
|
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("admin/new/api/v1/systemConfig")
|
public class SystemConfigAdminController {
|
|
@Resource
|
private SystemConfigService systemConfigService;
|
|
@Resource
|
private SystemService systemService;
|
|
@RequestMapping(value = "getSystemConfigList", method = RequestMethod.POST)
|
public void getSystemConfigList(int pageIndex, String platform,
|
String packages, String key, PrintWriter out) {
|
|
platform = Utils.getMap().get(platform);
|
System system = systemService.getSystem(platform, packages);
|
List<SystemConfig> systemConfigList = systemConfigService
|
.getSystemConfigList(pageIndex - 1, system, key);
|
int count = systemConfigService.getCount(system, key);
|
int totalPage = count % Constant.PAGE_SIZE == 0 ? count
|
/ Constant.PAGE_SIZE : count / Constant.PAGE_SIZE + 1;
|
PageEntity pe = new PageEntity(pageIndex, Constant.PAGE_SIZE, count,
|
totalPage);
|
Map<String, String> map = new HashMap<String, String>();
|
map.put("key", key);
|
pe.setParams(map);
|
JSONObject data = new JSONObject();
|
data.put("pe", pe);
|
List<System> systemList = systemService.getSystems();
|
data.put("systemList", systemList);
|
data.put("systemConfigList", systemConfigList);
|
out.print(JsonUtil.loadTrueResult(data));
|
}
|
|
@RequestMapping(value = "addSystemConfig", method = RequestMethod.POST)
|
public void addSystemConfig(@RequestBody SystemConfig sc, PrintWriter out) {
|
systemConfigService.addSystemConfig(sc);
|
out.print(JsonUtil.loadTrueResult("添加成功"));
|
}
|
@RequestMapping(value = "setSystem", method = RequestMethod.POST)
|
public void setSystem(long id, String type, String platform,
|
String packages, PrintWriter out) {
|
platform = Utils.getMap().get(platform);
|
System system = systemService.getSystem(platform, packages);
|
if (system == null) {
|
out.print(JsonUtil.loadFalseResult("不存在该系统"));
|
return;
|
}
|
try {
|
if (Constant.DEL.equals(type)) {
|
systemConfigService.deleteSystem(id, system);
|
} else {
|
systemConfigService.addSystem(id, system);
|
}
|
out.print(JsonUtil.loadTrueResult("操作成功"));
|
} catch (NotExistObjectException e) {
|
out.print(JsonUtil.loadFalseResult("操作失败"));
|
}
|
}
|
|
@RequestMapping(value = "getSystemConfig", method = RequestMethod.POST)
|
public void getSystemConfig(long id,PrintWriter out){
|
SystemConfig sc = systemConfigService.getSystemConfig(id);
|
if(sc==null){
|
out.print(JsonUtil.loadFalseResult("不存在该对象"));
|
return;
|
}
|
out.print(JsonUtil.loadTrueResult(sc));
|
}
|
|
@RequestMapping(value = "updateSystemConfig", method = RequestMethod.POST)
|
public void updateSystemConfig(@RequestBody SystemConfig sc,PrintWriter out){
|
try {
|
systemConfigService.updateSystemConfig(sc);
|
out.print(JsonUtil.loadTrueResult("修改成功"));
|
} catch (NotExistObjectException e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "deleteSystemConfig", method = RequestMethod.POST)
|
public void deleteSystemConfig(long[] ids,PrintWriter out){
|
for (long id : ids) {
|
systemConfigService.deleteSystemConfig(id);
|
}
|
out.print(JsonUtil.loadTrueResult("删除成功"));
|
}
|
|
@RequestMapping(value="get")
|
public void get(String key,PrintWriter out){
|
String value="";
|
try {
|
value = systemConfigService.get(key);
|
} catch (NotExistObjectException e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
return;
|
}
|
out.print(JsonUtil.loadTrueResult(value));
|
}
|
}
|