From 88b54772dbcf5ecab1e2316e4e4626ac901b8908 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期二, 22 一月 2019 15:58:24 +0800
Subject: [PATCH] 邀请码添加返回状态

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java |  207 ++++++++++++++++++++-------------------------------
 1 files changed, 82 insertions(+), 125 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java
index df38509..64ca441 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/LableAdminController.java
@@ -10,7 +10,6 @@
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import net.sf.json.JSONObject;
 
@@ -20,6 +19,7 @@
 import org.springframework.web.multipart.MultipartFile;
 import org.springframework.web.multipart.MultipartHttpServletRequest;
 import org.springframework.web.multipart.commons.CommonsMultipartFile;
+import org.yeshi.utils.JsonUtil;
 
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
@@ -35,8 +35,6 @@
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.TimeUtil;
-import com.yeshi.fanli.util.annotation.RequestNoLogin;
-import org.yeshi.utils.JsonUtil;
 
 @Controller
 @RequestMapping("admin/new/api/v1/lable")
@@ -61,59 +59,45 @@
 	 * @param request
 	 * @param out
 	 */
-	@RequestNoLogin()
 	@RequestMapping(value = "saveAdd")
-	public void saveAdd(String callback,Long uid, Label label,
-			HttpServletRequest request, PrintWriter out, HttpServletResponse response) {
-		response.setHeader("Access-Control-Allow-Origin", "*");
-		response.setHeader("Access-Control-Allow-Methods", "*");
-		
-		// // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛
-		AdminUser admin = adminUserService.selectByPrimaryKey(uid);
-		if (admin == null) {
-			out.print(JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄嗐��"));
-		} else {
+	public void saveAdd(String callback, Long uid, Label label, HttpServletRequest request, PrintWriter out) {
 
-			try {
-				String title = label.getTitle();
-				if (StringUtil.isNullOrEmpty(title)) {
-					out.print( JsonUtil.loadFalseResult("鏍囩鍚嶇О涓虹┖"));
-				} else {
-					
-					List<Label> labels = labelService.selectByTitle(title.trim());
-					
-					if (labels == null || labels.size() == 0) {
-						
-						label.setTitle(label.getTitle().trim());
-						
-						if(request instanceof	MultipartHttpServletRequest){
-							
-							List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
-							
-							if (files != null && files.size() > 0) {
-								labelService.insertSingle(label, admin, files.get(0));
-							} else {
-								labelService.insertSingle(label, admin, null);
-							}
-							
-						} else {
-							labelService.insertSingle(label, admin, null);
-						}
-						
-						out.print( JsonUtil.loadTrueResult("娣诲姞鎴愬姛"));
-						
-					} else {
-						out.print( JsonUtil.loadTrueResult("宸插瓨鍦ㄦ鏍囩"));
-					}
-				}
-				
-			} catch (Exception e) {
-				// TODO Auto-generated catch block
-				out.print(JsonUtil.loadFalseResult("鎿嶄綔寮傚父"));
-				e.printStackTrace();
+		try {
+			String title = label.getTitle();
+			if (StringUtil.isNullOrEmpty(title)) {
+				out.print(JsonUtil.loadFalseResult("鏍囩鍚嶇О涓虹┖"));
+				return;
 			}
-		}
 
+			List<Label> labels = labelService.selectByTitle(title.trim());
+			AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
+			if (labels == null || labels.size() == 0) {
+
+				label.setTitle(label.getTitle().trim());
+
+				if (request instanceof MultipartHttpServletRequest) {
+
+					List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("file");
+
+					if (files != null && files.size() > 0) {
+						labelService.insertSingle(label, admin, files.get(0));
+					} else {
+						labelService.insertSingle(label, admin, null);
+					}
+
+				} else {
+					labelService.insertSingle(label, admin, null);
+				}
+
+				out.print(JsonUtil.loadTrueResult("娣诲姞鎴愬姛"));
+
+			} else {
+				out.print(JsonUtil.loadTrueResult("宸插瓨鍦ㄦ鏍囩"));
+			}
+		} catch (Exception e) {
+			out.print(JsonUtil.loadFalseResult("鎿嶄綔寮傚父"));
+			e.printStackTrace();
+		}
 	}
 	
 	
@@ -126,44 +110,36 @@
 	 * @param out
 	 */
 	@RequestMapping(value = "addBatch")
-	public void addBatch(String callback, String param,
-			HttpServletRequest request, PrintWriter out) {
-		// // 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛
-		AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
+	public void addBatch(String callback, String param,	HttpServletRequest request, PrintWriter out) {
 
-		if (admin == null) {
-			out.print(JsonUtil.loadJSONP(callback,JsonUtil.loadFalseResult("褰撳墠璐︽埛宸插け鏁�,璇烽噸鏂扮櫥闄嗐��")));
-		} else {
-
-			try {
-				Gson gson = new Gson();
-				List<Label> labs = gson.fromJson(param,	new TypeToken<ArrayList<Label>>() {}.getType());
+		try {
+			Gson gson = new Gson();
+			List<Label> labs = gson.fromJson(param,	new TypeToken<ArrayList<Label>>() {}.getType());
+		
+			List<Label> newList = new ArrayList<Label>();
+			if (labs == null || labs.size() == 0) {
+				out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈绱㈠埌鏁版嵁")));
+				return;
+			} 
 			
-				List<Label> newList = new ArrayList<Label>();
-				if (labs == null || labs.size() == 0) {
-					out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鏈绱㈠埌鏁版嵁")));
-				} else {
-					for (Label label: labs) {
-						String title = label.getTitle();
-						if (!StringUtil.isNullOrEmpty(title)) {
-							
-							List<Label> labels = labelService.selectByTitle(title.trim());
-							if (labels == null || labels.size() == 0) {
-								newList.add(label);
-							}
-						}
+			for (Label label: labs) {
+				String title = label.getTitle();
+				if (!StringUtil.isNullOrEmpty(title)) {
+					
+					List<Label> labels = labelService.selectByTitle(title.trim());
+					if (labels == null || labels.size() == 0) {
+						newList.add(label);
 					}
 				}
-				
-
-				labelService.insertList(newList, admin);
-
-				out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("娣诲姞鎴愬姛")));
-			} catch (LabelException e) {
-				// TODO Auto-generated catch block
-				out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("娣诲姞寮傚父")));
-				e.printStackTrace();
 			}
+			
+			AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
+			labelService.insertList(newList, admin);
+
+			out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult("娣诲姞鎴愬姛")));
+		} catch (LabelException e) {
+			out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("娣诲姞寮傚父")));
+			e.printStackTrace();
 		}
 
 	}
@@ -179,7 +155,7 @@
 	 * @param out
 	 */
 	@RequestMapping(value = "saveModify")
-	public void saveModify(String callback, Label label, HttpServletRequest request,PrintWriter out) {
+	public void saveModify(String callback, Label label, PrintWriter out) {
 		
 		try {
 			Long id = label.getId();
@@ -246,7 +222,6 @@
 			}
 			
 		} catch (LabelException e) {
-			// TODO Auto-generated catch block
 			out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("鍒犻櫎澶辫触")));
 			e.printStackTrace();
 		}
@@ -262,34 +237,25 @@
 	 * @param out
 	 * @param response
 	 */
-	@RequestNoLogin()
 	@RequestMapping(value = "uploadFile")
-	public void uploadFile(@RequestParam("file") CommonsMultipartFile file, Long uid,
-			HttpServletRequest request, PrintWriter out,HttpServletResponse response) {
-		// 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛
-		response.setHeader("Access-Control-Allow-Origin", "*");
-		response.setHeader("Access-Control-Allow-Methods", "*");
-		
-		AdminUser admin = adminUserService.selectByPrimaryKey(uid);
-		
-		if (admin == null) {
-			out.print( JsonUtil.loadFalseResult("褰撳墠璐︽埛澶辨晥,璇烽噸鏂扮櫥闄嗐��"));
-		} else {
-			if (file == null) {
-				out.print(JsonUtil.loadFalseResult("鏂囦欢涓嶈兘涓虹┖!"));
-			} else {
-				
-				try {
-					labelService.analysisExcel(file.getInputStream(), admin);
-					out.print((JsonUtil.loadTrueResult("涓婁紶鎴愬姛")));
-					//response.getWriter().print(JsonUtil.loadTrueResult("涓婁紶鎴愬姛"));
-				} catch (Exception e) {
-					e.printStackTrace();
-					out.print((JsonUtil.loadFalseResult("涓婁紶澶辫触")));
-				}
-				
-			}
-			
+	public void uploadFile(@RequestParam("file") CommonsMultipartFile file,	HttpServletRequest request,
+			PrintWriter out) {
+
+		if (file == null) {
+			out.print(JsonUtil.loadFalseResult("鏂囦欢涓嶈兘涓虹┖!"));
+			return;
+		}
+
+		try {
+			AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
+			labelService.analysisExcel(file.getInputStream(), admin);
+
+			out.print((JsonUtil.loadTrueResult("涓婁紶鎴愬姛")));
+			// response.getWriter().print(JsonUtil.loadTrueResult("涓婁紶鎴愬姛"));
+
+		} catch (Exception e) {
+			e.printStackTrace();
+			out.print((JsonUtil.loadFalseResult("涓婁紶澶辫触")));
 		}
 
 	}
@@ -303,16 +269,9 @@
 	 * @param out
 	 * @param response
 	 */
-	@RequestNoLogin()
 	@RequestMapping(value = "uploadImg")
-	public void uploadImg(Long id, @RequestParam("file") CommonsMultipartFile file, 
-			HttpServletRequest request, PrintWriter out, HttpServletResponse response) {
+	public void uploadImg(Long id, @RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
 
-		response.setHeader("Access-Control-Allow-Origin", "*");
-		response.setHeader("Access-Control-Allow-Methods", "*");
-
-		// 鑾峰彇褰撳墠鎿嶄綔鐢ㄦ埛
-	
 		try {
 			Label label = labelService.selectByPrimaryKey(id);
 
@@ -336,7 +295,6 @@
 			}
 
 		} catch (Exception e) {
-			// TODO Auto-generated catch block
 			e.printStackTrace();
 			out.print(JsonUtil.loadFalseResult("鎿嶄綔澶辫触"));
 		}
@@ -352,8 +310,7 @@
 	 * @param response
 	 */
 	@RequestMapping(value = "deleteImg")
-	public void deleteImg(String callback, Long id, HttpServletRequest request, PrintWriter out,
-			HttpServletResponse response) {
+	public void deleteImg(String callback, Long id, PrintWriter out) {
 
 		try {
 			Label label = labelService.selectByPrimaryKey(id);

--
Gitblit v1.8.0