From 73a3d86a47d8da711b609cd224c63526f7d00f9b Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 22 七月 2020 12:49:06 +0800
Subject: [PATCH] 比价相关的bug修复

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/order/TaoBaoOrderController.java |  337 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 191 insertions(+), 146 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/order/TaoBaoOrderController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/order/TaoBaoOrderController.java
index e20b294..1e6d998 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/order/TaoBaoOrderController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/order/TaoBaoOrderController.java
@@ -1,193 +1,238 @@
 package com.yeshi.fanli.controller.admin.order;
 
-import java.io.PrintWriter;
-import java.lang.reflect.Type;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.annotation.Resource;
-
+import com.google.gson.*;
+import com.yeshi.common.entity.PageEntity;
 import com.yeshi.fanli.entity.accept.AdminAcceptData;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.yeshi.utils.JsonUtil;
-
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonPrimitive;
-import com.google.gson.JsonSerializationContext;
-import com.google.gson.JsonSerializer;
 import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
 import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
 import com.yeshi.fanli.job.order.taobao.UpdateOrderJob;
 import com.yeshi.fanli.job.order.taobao.UpdateTBRelationAndSpecialOrderJob;
+import com.yeshi.fanli.service.inter.order.OrderProcessService;
 import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
 import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
-import com.yeshi.common.entity.PageEntity;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.ThreadUtil;
+import com.yeshi.fanli.util.taobao.TaoBaoOrderUtil;
+import net.sf.json.JSONObject;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+import org.yeshi.utils.JsonUtil;
 import org.yeshi.utils.TimeUtil;
 
-import net.sf.json.JSONObject;
+import javax.annotation.Resource;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.lang.reflect.Type;
+import java.util.*;
 
 @Controller
 @RequestMapping("admin/new/api/v1/taobaoOrder")
 public class TaoBaoOrderController {
 
-	@Resource
-	private TaoBaoOrderService taoBaoOrderService;
+    @Resource
+    private TaoBaoOrderService taoBaoOrderService;
 
-	@Resource
-	private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
+    @Resource
+    private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
 
-	@Resource
-	private UpdateTBRelationAndSpecialOrderJob updateRelationAndSpecialOrderJob;
+    @Resource
+    private UpdateTBRelationAndSpecialOrderJob updateRelationAndSpecialOrderJob;
 
-	@Resource
-	private UpdateOrderJob updateOrderJob;
+    @Resource
+    private UpdateOrderJob updateOrderJob;
 
-	/**
-	 * 鏌ヨ鍒楄〃 - 鏂板悗鍙�
-	 * 
-	 * @param callback
-	 * @param key
-	 *            鏌ヨ璇� 鍚嶇О
-	 * @param pageIndex
-	 * @param out
-	 */
-	@RequestMapping(value = "listTaoBaoOrder")
-	public void listTaoBaoOrder(AdminAcceptData acceptData, String callback, String key, Integer pageIndex, PrintWriter out) {
+    @Resource
+    private OrderProcessService orderProcessService;
 
-		try {
+    /**
+     * 鏌ヨ鍒楄〃 - 鏂板悗鍙�
+     *
+     * @param callback
+     * @param key       鏌ヨ璇� 鍚嶇О
+     * @param pageIndex
+     * @param out
+     */
+    @RequestMapping(value = "listTaoBaoOrder")
+    public void listTaoBaoOrder(AdminAcceptData acceptData, String callback, String key, Integer pageIndex, PrintWriter out) {
 
-			if (pageIndex == null || pageIndex < 0) {
-				pageIndex = 1;
-			}
+        try {
 
-			List<TaoBaoOrder> orderList = null;
-			Long count = null;
+            if (pageIndex == null || pageIndex < 0) {
+                pageIndex = 1;
+            }
 
-			if (!StringUtil.isNullOrEmpty(key)) {
-				orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(key);
-				count = (long) orderList.size();
-			} else {
-				orderList = taoBaoOrderService.listAllOrder(pageIndex, Constant.PAGE_SIZE);
-				count = taoBaoOrderService.countAllOrder();
-			}
+            List<TaoBaoOrder> orderList = null;
+            Long count = null;
 
-			int pageSize = Constant.PAGE_SIZE;
+            if (!StringUtil.isNullOrEmpty(key)) {
+                orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(key);
+                count = (long) orderList.size();
+            } else {
+                orderList = taoBaoOrderService.listAllOrder(pageIndex, Constant.PAGE_SIZE);
+                count = taoBaoOrderService.countAllOrder();
+            }
 
-			int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
-			PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
+            int pageSize = Constant.PAGE_SIZE;
 
-			Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
-				@Override
-				public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
-					if (value == null) {
-						return new JsonPrimitive("");
-					} else {
-						return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
-					}
-				}
-			}).create();
+            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", gson.toJson(orderList));
+            Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
+                @Override
+                public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
+                    if (value == null) {
+                        return new JsonPrimitive("");
+                    } else {
+                        return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
+                    }
+                }
+            }).create();
 
-			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
+            JSONObject data = new JSONObject();
+            data.put("pe", pe);
+            data.put("result_list", gson.toJson(orderList));
 
-		} catch (Exception e) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触"));
-			e.printStackTrace();
-		}
-	}
+            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 
-	@RequestMapping(value = "updateTaoBaoOrder")
-	public void updateTaoBaoOrder(AdminAcceptData acceptData,String callback, String ids, PrintWriter out) {
-		try {
-			if (StringUtil.isNullOrEmpty(ids)) {
-				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇蜂笂浼犺鍗旾D"));
-				return;
-			}
-			net.sf.json.JSONArray idsArray = net.sf.json.JSONArray.fromObject(ids);
+        } catch (Exception e) {
+            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触"));
+            e.printStackTrace();
+        }
+    }
 
-			Set<String> orderIds = new HashSet<>();
+    @RequestMapping(value = "updateTaoBaoOrder")
+    public void updateTaoBaoOrder(AdminAcceptData acceptData, String callback, String ids, PrintWriter out) {
+        try {
+            if (StringUtil.isNullOrEmpty(ids)) {
+                JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇蜂笂浼犺鍗旾D"));
+                return;
+            }
+            net.sf.json.JSONArray idsArray = net.sf.json.JSONArray.fromObject(ids);
 
-			for (int i = 0; i < idsArray.size(); i++) {
-				TaoBaoOrder taoBaoOrder = taoBaoOrderService.selectByPrimaryKey(idsArray.optLong(i));
-				orderIds.add(taoBaoOrder.getOrderId());
-			}
+            Set<String> orderIds = new HashSet<>();
 
-			Long[] startTimes = new Long[orderIds.size()];
-			Long[] endTimes = new Long[orderIds.size()];
+            for (int i = 0; i < idsArray.size(); i++) {
+                TaoBaoOrder taoBaoOrder = taoBaoOrderService.selectByPrimaryKey(idsArray.optLong(i));
+                orderIds.add(taoBaoOrder.getOrderId());
+            }
 
-			int p = 0;
-			for (Iterator<String> its = orderIds.iterator(); its.hasNext();) {
-				String orderId = its.next();
-				List<TaoBaoOrder> list = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
-				startTimes[p] = TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") - 1000L;
-				endTimes[p] = TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") + 1000L;
-				p++;
-			}
+            Long[] startTimes = new Long[orderIds.size()];
+            Long[] endTimes = new Long[orderIds.size()];
 
-			for (int i = 0; i < idsArray.size(); i++) {
-				updateRelationAndSpecialOrderJob.updateRelationAndSpecialOrder(startTimes[i], endTimes[i]);
-				updateOrderJob.updateOrder(startTimes[i], endTimes[i]);
-			}
-			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鏇存柊鎴愬姛"));
-		} catch (Exception e) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏇存柊澶辫触"));
-			e.printStackTrace();
-		}
-	}
+            int p = 0;
+            for (Iterator<String> its = orderIds.iterator(); its.hasNext(); ) {
+                String orderId = its.next();
+                List<TaoBaoOrder> list = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
+                startTimes[p] = TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") - 1000L;
+                endTimes[p] = TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") + 1000L;
+                p++;
+            }
 
-	@RequestMapping(value = "listTaoBaoWQOrder")
-	public void listTaoBaoWeiQuanOrder(AdminAcceptData acceptData,String callback, String key, Integer pageIndex, PrintWriter out) {
-		try {
-			if (pageIndex == null || pageIndex < 0) {
-				pageIndex = 1;
-			}
-			List<TaoBaoWeiQuanOrder> orderList = null;
-			Long count = null;
-			if (!StringUtil.isNullOrEmpty(key)) {
-				orderList = taoBaoWeiQuanOrderService.listByOrderId(key);
-				count = (long) orderList.size();
-			} else {
-				orderList = taoBaoWeiQuanOrderService.listByState(null, pageIndex, Constant.PAGE_SIZE);
-				count = taoBaoWeiQuanOrderService.countByState(null);
-			}
+            for (int i = 0; i < idsArray.size(); i++) {
+                updateRelationAndSpecialOrderJob.updateRelationAndSpecialOrder(startTimes[i], endTimes[i]);
+                updateOrderJob.updateOrder(startTimes[i], endTimes[i]);
+            }
+            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鏇存柊鎴愬姛"));
+        } catch (Exception e) {
+            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏇存柊澶辫触"));
+            e.printStackTrace();
+        }
+    }
 
-			int pageSize = Constant.PAGE_SIZE;
+    @RequestMapping(value = "listTaoBaoWQOrder")
+    public void listTaoBaoWeiQuanOrder(AdminAcceptData acceptData, String callback, String key, Integer pageIndex, PrintWriter out) {
+        try {
+            if (pageIndex == null || pageIndex < 0) {
+                pageIndex = 1;
+            }
+            List<TaoBaoWeiQuanOrder> orderList = null;
+            Long count = null;
+            if (!StringUtil.isNullOrEmpty(key)) {
+                orderList = taoBaoWeiQuanOrderService.listByOrderId(key);
+                count = (long) orderList.size();
+            } else {
+                orderList = taoBaoWeiQuanOrderService.listByState(null, pageIndex, Constant.PAGE_SIZE);
+                count = taoBaoWeiQuanOrderService.countByState(null);
+            }
 
-			int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
-			PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
+            int pageSize = Constant.PAGE_SIZE;
 
-			Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
-				@Override
-				public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
-					if (value == null) {
-						return new JsonPrimitive("");
-					} else {
-						return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
-					}
-				}
-			}).create();
+            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", gson.toJson(orderList));
+            Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
+                @Override
+                public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
+                    if (value == null) {
+                        return new JsonPrimitive("");
+                    } else {
+                        return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
+                    }
+                }
+            }).create();
 
-			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
+            JSONObject data = new JSONObject();
+            data.put("pe", pe);
+            data.put("result_list", gson.toJson(orderList));
 
-		} catch (Exception e) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触"));
-			e.printStackTrace();
-		}
-	}
+            JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 
+        } catch (Exception e) {
+            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触"));
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     * 鏂板悗鍙扮 涓婁紶璁㈠崟鏂囦欢
+     *
+     * @param acceptData
+     * @param file
+     * @param out
+     */
+    @RequestMapping(value = "uploadWQOrderFile")
+    public void uploadWQOrderFile(AdminAcceptData acceptData, @RequestParam("file") CommonsMultipartFile file, PrintWriter out) {
+
+        if (file == null) {
+            out.print(JsonUtil.loadFalseResult("涓婁紶鏂囦欢涓嶈兘涓虹┖"));
+            return;
+        }
+
+        List<TaoBaoWeiQuanOrder> orderList = null;
+        try {
+            orderList = TaoBaoOrderUtil.parseWeiQuanOrder(
+                    file.getInputStream());
+            int pos = 0;
+            for (TaoBaoWeiQuanOrder order : orderList)
+                try {
+                    pos++;
+                    // if (pos == 19||pos == 26)
+                    taoBaoWeiQuanOrderService.addWeiQuanOrder(order);// 娣诲姞缁存潈璁㈠崟鍒版暟鎹簱
+                } catch (Exception e) {
+                    System.out.println("浣嶇疆:" + pos);
+                    e.printStackTrace();
+                }
+            // 澶勭悊缁存潈璁㈠崟
+            out.print(JsonUtil.loadTrueResult("涓婁紶鎴愬姛,绯荤粺姝e湪澶勭悊涓�..."));
+        } catch (IOException e) {
+            out.print(JsonUtil.loadFalseResult("涓婁紶鏂囦欢澶辫触"));
+            e.printStackTrace();
+        }
+
+        final List<TaoBaoWeiQuanOrder> finalOrderList = orderList;
+
+        ThreadUtil.run(new Runnable() {
+            @Override
+            public void run() {
+                orderProcessService.weiQuanOrder(finalOrderList);
+            }
+        });
+
+    }
 }

--
Gitblit v1.8.0