From eed607d87b2eee1f09b4a28da614f3ad0b46601d Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 14 三月 2019 16:14:37 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java |  111 ++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 89 insertions(+), 22 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java
index 7bd8784..f48680f 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/ConfigAdminController.java
@@ -7,13 +7,19 @@
 
 import javax.annotation.Resource;
 
+import net.sf.json.JSONObject;
+
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.yeshi.utils.JsonUtil;
 
 import com.yeshi.fanli.entity.common.Config;
+import com.yeshi.fanli.service.AdminUserService;
 import com.yeshi.fanli.service.inter.config.ConfigService;
-import org.yeshi.utils.JsonUtil;
+import com.yeshi.fanli.tag.PageEntity;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
 
 @Controller
 @RequestMapping("admin/new/api/v1/config")
@@ -22,29 +28,90 @@
 	@Resource
 	private ConfigService configService;
 	
-	@RequestMapping(value = "getConfigList", method = RequestMethod.POST)
-	public void getConfigList(PrintWriter out){
-		List<Config> configList =  configService.getAllList();
-		out.print(JsonUtil.loadTrueResult(configList));
+	
+	/**
+	 * 鏌ヨ鍒楄〃 - 鏂板悗鍙�
+	 * @param callback
+	 * @param key 鏌ヨ璇�  鍚嶇О
+	 * @param pageIndex
+	 * @param out
+	 */
+	@RequestMapping(value = "getNewConfigList")
+	public void getNewConfigList(String callback, String key, Integer pageIndex, PrintWriter out){
+		
+		try {
+			
+			if (pageIndex == null || pageIndex < 0){
+				pageIndex = 1;
+			}
+			
+			List<Config> list =  configService.listObjects(key, pageIndex);
+			
+			if (list == null || list.size() == 0) {
+				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏇村鏁版嵁"));
+				return;
+			}
+			
+			int pageSize = Constant.PAGE_SIZE;
+			
+			int count = configService.getCount(key, pageIndex);
+			int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
+			PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
+			
+			JSONObject data = new JSONObject();
+			data.put("pe", pe);
+			data.put("result_list", list);
+			
+			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
+			
+		} catch (Exception e) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触"));
+			e.printStackTrace();
+		}
 	}
 	
-	@RequestMapping(value = "updateConfig", method = RequestMethod.POST)
-	public void updateConfig(String map, PrintWriter out) {
-		List<Config> list = configService.getAllList();
-		List<Config> newList = new ArrayList<Config>();
-		Map<String, String> data = JsonUtil.parseData(map);
-		for (Config config : list) {
-			String key = config.getKey();
-			if(data.containsKey(key)){
-				String value =data.get(key);
-				if(!config.getValue().equals(value)){
-					config.setValue(value);
-					newList.add(config);
-				}
-			}
+	/**
+	 * 鍙傛暟淇敼 - 鏂板悗鍙�
+	 * @param callback
+	 * @param config
+	 * @param out
+	 */
+	@RequestMapping(value = "saveModify")
+	public void saveModify(String callback, Config config, PrintWriter out) {
+
+		Long id = config.getId();
+		if (id == null) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("ID涓嶈兘涓虹┖"));
+			return;
 		}
-		configService.update(newList);
-		out.print(JsonUtil.loadTrueResult("淇敼鎴愬姛"));
-		return;
+		
+		try {
+			Config crentconfig = configService.getConfig(id);
+			if (crentconfig == null) {
+				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔鏁版嵁宸蹭笉瀛樺湪"));
+				return;
+			}
+			
+			if (StringUtil.isNullOrEmpty(config.getName()) || StringUtil.isNullOrEmpty(config.getValue())) {
+				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇存槑銆佹湁鏁堝�间笉鑳戒负绌�"));
+				return;
+			}
+			
+			crentconfig.setName(config.getName());
+			crentconfig.setValue(config.getValue());
+			
+			if (!StringUtil.isNullOrEmpty(config.getBeizhu())) {
+				crentconfig.setBeizhu(config.getBeizhu());
+			}
+			
+			configService.update(crentconfig);
+			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("淇敼鎴愬姛"));
+			
+		} catch (Exception e) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("淇敼澶辫触"));
+			e.printStackTrace();
+		}
+		
 	}
+	
 }

--
Gitblit v1.8.0