From 718ddb45b7f05a1d37c18ab7c3fc7862a2aa7d06 Mon Sep 17 00:00:00 2001
From: 喻健 <喻健@Admin>
Date: 星期五, 16 十一月 2018 10:45:38 +0800
Subject: [PATCH] 热门搜索迁移

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/UploadController.java |   76 ++++++++++++++++++++++++++++++++++---
 1 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/UploadController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/UploadController.java
index 75c30ca..cd690db 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/UploadController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/UploadController.java
@@ -12,6 +12,7 @@
 
 import net.sf.json.JSONObject;
 
+import org.springframework.core.task.TaskExecutor;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -27,6 +28,7 @@
 import com.yeshi.fanli.service.inter.order.OrderProcessService;
 import com.yeshi.fanli.service.inter.order.OrderService;
 import com.yeshi.fanli.util.TimeUtil;
+import com.yeshi.fanli.util.annotation.RequestNoLogin;
 import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
 
 @Controller
@@ -44,6 +46,10 @@
 	
 	@Resource
 	private AdminUserService adminUserService;
+	
+	@Resource(name = "taskExecutor")
+	private TaskExecutor executor;
+	
 	
 
 	// private static final String PAYSUCCESS = "鏀粯鎴愬姛";
@@ -146,6 +152,7 @@
 	 * @param response
 	 * @param out
 	 */
+	@RequestNoLogin()
 	@RequestMapping(value = "uploadOrderFile")
 	public void uploadOrderFile(@RequestParam("file") CommonsMultipartFile file, Long uid,
 			 HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
@@ -164,17 +171,72 @@
 			return;
 		}
 		
+		List<TaoBaoOrder> orderList = null ;
 		try {
-			List<TaoBaoOrder> orderList = TaoBaoOrderUtil.parseOrder(file.getInputStream());
-			
-			orderProcessService.processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(orderList));
-			
-			out.print(JsonUtil.loadTrueResult("涓婁紶鎴愬姛"));
-		
+			orderList = TaoBaoOrderUtil.parseOrder(file.getInputStream());
+			out.print(JsonUtil.loadTrueResult("涓婁紶鏂囦欢鎴愬姛"));
 		} catch (IOException e) {
+			out.print(JsonUtil.loadFalseResult("涓婁紶鏂囦欢澶辫触"));
 			e.printStackTrace();
-			out.print(JsonUtil.loadFalseResult("涓婁紶寮傚父"));
 		}
+		
+		final List<TaoBaoOrder> list = orderList;
+		
+		executor.execute(new Runnable() {
+			@Override
+			public void run() {
+				try {
+					
+					orderProcessService.processOrder(TaoBaoOrderUtil.classifyTaoBaoOrderByOrderId(list));
+					
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+
+			}
+		});
+			
 	}
 	
+	
+	/**
+	 * 涓婁紶鍥剧墖jsonp
+	 * @param file 
+	 * @param out 
+	 */
+	@RequestNoLogin()
+	@RequestMapping(value = "uploadPicture")
+	public void uploadPicture(@RequestParam("file") CommonsMultipartFile file, Long uid, 
+			HttpServletResponse response, PrintWriter out) {
+	
+		response.setHeader("Access-Control-Allow-Origin", "*");
+		response.setHeader("Access-Control-Allow-Methods", "*");
+
+		AdminUser admin = adminUserService.selectByPrimaryKey(uid);
+		if (admin == null) {
+			out.print(JsonUtil.loadFalseResult("褰撳墠璐︽埛楠岃瘉澶辫触"));
+			return;
+		}
+		
+		if (file == null) {
+			out.print(JsonUtil.loadFalseResult("涓婁紶鏂囦欢涓虹┖"));
+			return;
+		}
+		
+		try {
+			InputStream inputStream = file.getInputStream();
+			String contentType = file.getContentType();
+			String type = contentType.substring(contentType.indexOf("/") + 1);
+			// 涓婁紶鏂囦欢鐩稿浣嶇疆
+			String fileUrl=UUID.randomUUID().toString().replace("-", "") + "." + type;
+			
+			String uploadPath = COSManager.getInstance().uploadFile(inputStream, fileUrl).getUrl();
+			
+			out.print(JsonUtil.loadTrueResult(uploadPath));
+			
+		} catch (IOException e) {
+			out.print(JsonUtil.loadFalseResult("涓婁紶鍥剧墖澶辫触"));
+			e.printStackTrace();
+		}
+	}
 }

--
Gitblit v1.8.0