From 4e7bcd65a96e0c00ff228677649986b682fee0d3 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期五, 11 一月 2019 16:17:33 +0800
Subject: [PATCH] 订单接口优化

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java |  152 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 131 insertions(+), 21 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
index 96969f8..97c11df 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/OrderAdminController.java
@@ -1,6 +1,7 @@
 package com.yeshi.fanli.controller.admin;
 
 import java.io.PrintWriter;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -17,14 +18,18 @@
 
 import com.google.gson.Gson;
 import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.controller.admin.utils.AdminUtils;
 import com.yeshi.fanli.entity.admin.OrderAdmin;
+import com.yeshi.fanli.exception.order.CommonOrderException;
 import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoService;
 import com.yeshi.fanli.service.inter.order.CommonOrderCountService;
+import com.yeshi.fanli.service.inter.order.CommonOrderService;
 import com.yeshi.fanli.service.inter.order.OrderService;
 import com.yeshi.fanli.tag.PageEntity;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.vo.order.CommonOrderVO;
 
 @Controller
 @RequestMapping("admin/new/api/v1/order")
@@ -41,6 +46,10 @@
 	
 	@Resource
 	private CommonOrderCountService commonOrderCountService;
+	
+	@Resource
+	private CommonOrderService commonOrderService;
+	
 
 	@RequestMapping(value = "getOrderList", method = RequestMethod.POST)
 	public void getOrderList(int pageIndex, String key, PrintWriter out) {
@@ -52,6 +61,62 @@
 		data.put("pe", pe);
 		data.put("orderList", JsonUtil.getSimpleGsonWithDateAndSerialization().toJson(orderAdminList));
 		out.print(JsonUtil.loadTrueResult(data));
+	}
+	
+	
+
+	@RequestMapping(value = "getHistoryOrder")
+	public void getHistoryOrder(String callback, Integer pageIndex, Integer pageSize, Long uid, Integer state, Integer type, 
+			Integer orderState,	String orderNo, String startTime, String endTime, PrintWriter out) {
+
+		if (uid == null) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("uid涓嶈兘涓虹┖"));
+			return;
+		}
+
+		if (pageIndex == null || pageIndex < 1) {
+			pageIndex = 1;
+		}
+		
+		if (pageSize == null)
+			pageSize = Constant.PAGE_SIZE;
+
+		if (state != null && state == 0) {
+			state = null;// 鎵�鏈夌姸鎬�
+		}
+
+		if (type != null && type == 0) {
+			type = null; // 鎵�鏈夌被鍨嬭鍗�
+		}
+
+		try {
+			long count = 0;
+
+			// 鏌ヨ鍒楄〃
+			List<CommonOrderVO> list = commonOrderService.listQueryByUid((pageIndex - 1) * pageSize, pageSize , 
+					uid, state, type, orderState, orderNo, startTime, endTime, null);
+
+			if (list != null && list.size() > 0) {
+				// 缁熻鎬绘暟
+				count = commonOrderService.countQueryByUid(uid, state, type, orderState, orderNo, startTime,
+						endTime, null);
+			}
+			
+			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 (CommonOrderException e) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
+		} catch (Exception e) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏌ヨ澶辫触"));
+			e.printStackTrace();
+		}
 	}
 
 	/**
@@ -199,7 +264,7 @@
 		}
 
 		try {
-			JSONObject data = countHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
+			JSONObject data = countHistoryHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
 			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 		} catch (Exception e) {
 			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("绯荤粺寮傚父"));
@@ -222,14 +287,15 @@
 	public void getHongBaoMoney(String callback,String channelArray, Integer dateType, Integer state,
 			String year, String startTime, String endTime, PrintWriter out) {
 
-		String validateMsg = validateParams(dateType, startTime, endTime);
+		String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
 		if (validateMsg != null) {
 			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
 			return;
 		}
-
+		
 		try {
-			JSONObject data = countHongBao( channelArray, dateType, state, year, startTime, endTime, 2);
+			
+			JSONObject data = countHistoryHongBao(channelArray, dateType, state, year, startTime,  endTime, 1);
 			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 		} catch (Exception e) {
 			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("绯荤粺寮傚父"));
@@ -237,6 +303,10 @@
 		}
 	}
 
+	
+	
+	
+	
 	
 
 	
@@ -251,7 +321,7 @@
 	 * @return
 	 * @throws Exception
 	 */
-	public JSONObject countHongBao(String channelArray, Integer dateType, Integer state, String year, String startTime,
+	public JSONObject countHistoryHongBao(String channelArray, Integer dateType, Integer state, String year, String startTime,
 			String endTime, int countType) throws Exception {
 
 		if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
@@ -259,6 +329,7 @@
 			endTime = null;
 		}
 
+		
 		List<String> channelList = null;
 		if (channelArray != null && channelArray.trim().length() > 0) {
 			Gson gson = new Gson();
@@ -270,34 +341,73 @@
 			channelList.add("all");
 		}
 
-		JSONArray array = new JSONArray();
-		for (String channel : channelList) {
-			JSONObject channelData = new JSONObject();
-
+		
+		if (dateType == 1 && year != null) {
+			year = null; // 璁剧疆涓虹┖
+		} else if (dateType == 2) {
+			if (startTime != null) 
+				startTime = null; 
 			
-			List<Map<String, Object>> resultList = null;
+			if (endTime != null) 
+				endTime = null; 
+			
+		} else if (dateType == 3) {
+			if (year != null)
+				year = null; 
+			
+			if (startTime != null) 
+				startTime = null; 
+			
+			if (endTime != null) 
+				endTime = null; 
+		}
+		
+		Gson gson = new Gson();
+		Object objectDate = null;
+		List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
+		
+		JSONArray line_list = new JSONArray();
+		for (String channel : channelList) {
+			List<Map<String, Object>> list = null;
 			if (countType == 1 ) {
-				resultList = hongBaoV2CountService.countHongBaoNum(channel, dateType, state, year, 
+				list = hongBaoV2CountService.countHongBaoNum(channel, dateType, state, year, 
 						startTime, endTime);
 			} else if (countType == 2) {
-				resultList = hongBaoV2CountService.countHongBaoMoney(channel, dateType, state, year, 
+				list = hongBaoV2CountService.countHongBaoMoney(channel, dateType, state, year, 
 						startTime, endTime);
 			}
-
-			if (resultList == null) {
-				resultList = new ArrayList<Map<String, Object>>();
-			}
-
+			
 			if ("all".equalsIgnoreCase(channel)) {
 				channel = "鎬昏";
 			}
-			channelData.put("name", channel);
-			channelData.put("data_list", resultList);
-			array.add(channelData);
+			
+			JSONObject innerList = new JSONObject();
+			innerList.put("name", channel);
+
+			if (dateType != 3) {
+				innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateList, list)));
+			} else {
+				// 骞磋鍥�
+				Map<String, Object> map = AdminUtils.yearsDataFactory(list);
+
+				if (objectDate == null) {
+					objectDate = map.get("date");
+				}
+				innerList.put("data", gson.toJson(map.get("value")));
+			}
+			
+			line_list.add(innerList);
 		}
 
+
 		JSONObject data = new JSONObject();
-		data.put("result_list", array);
+		if (objectDate != null) {
+			data.put("xAxis_list", gson.toJson(objectDate));
+		} else {
+			data.put("xAxis_list", gson.toJson(dateList));
+		}
+		
+		data.put("line_list", line_list);
 		
 		return data;
 	}

--
Gitblit v1.8.0