From 92c681fabac989d1a9f16fa13202d7f5ccac52d9 Mon Sep 17 00:00:00 2001
From: yujian <yujian>
Date: 星期一, 14 一月 2019 10:22:22 +0800
Subject: [PATCH] 订单优化 + 后台提现曲线图

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java |  223 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 138 insertions(+), 85 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java
index 1bdd638..3fddce4 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/UserInfoAdminController.java
@@ -33,6 +33,7 @@
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.controller.admin.utils.AdminUtils;
 import com.yeshi.fanli.entity.admin.UserInfoAdmin;
 import com.yeshi.fanli.entity.bus.user.AccountDetails;
 import com.yeshi.fanli.entity.bus.user.Extract;
@@ -1191,38 +1192,95 @@
 	public void getSameDayUserByChannel(String callback, String channelArray, Integer dateType, 
 		 String year, String startTime, String endTime, PrintWriter out) {
 		
-		validateParams(callback, channelArray, dateType,year,startTime,endTime,out);
+		
+		String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
+		if (validateMsg != null) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
+			return;
+		}
 		
 		if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
 			startTime = null;
 			endTime = null;
 		}
 		
+		List<String> channelList = null;
+		if (channelArray != null && channelArray.trim().length() > 0) {
+			Gson gson = new Gson();
+			channelList = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
+		}
+
+		if (channelList == null || channelList.size() == 0) {
+			channelList = new ArrayList<String>();
+			channelList.add("all");
+		}
+
+		
+		if (dateType == 1 && year != null) {
+			year = null; // 璁剧疆涓虹┖
+		} else if (dateType == 2) {
+			if (startTime != null) 
+				startTime = 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; 
+		}
+		
+		
 		try {
 
 			Gson gson = new Gson();
-			List<String> list = gson.fromJson(channelArray, new TypeToken<ArrayList<String>>() {}.getType());
-
-			if (list == null || list.size() == 0) {
-				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鍙傛暟鏍煎紡涓嶆纭�"));
-				return;
-			}
+			Object objectDate = null;
+			List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
 			
-			JSONArray array = new JSONArray();
-
-			for (String channel: list) {
-				JSONObject channelData = new JSONObject();
-				List<Object> resultList = userActiveLogService.countSameDayByChannel(channel, dateType, year, startTime, endTime);
-				if (resultList == null) {
-					resultList = new ArrayList<Object>();
+			JSONArray line_list = new JSONArray();
+			for (String channel : channelList) {
+				
+				List<Map<String, Object>> list = userActiveLogService.countSameDayByChannel(channel, 
+						dateType, year, startTime, endTime);
+				
+				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();
+			if (objectDate != null) {
+				data.put("xAxis_list", gson.toJson(objectDate));
+			} else {
+				data.put("xAxis_list", gson.toJson(dateList));
 			}
 			
-			JSONObject data = new JSONObject();
-			data.put("result_list", array);
+			data.put("line_list", line_list);
+			
 			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 
 		} catch (Exception e) {
@@ -1244,8 +1302,6 @@
 	@RequestMapping(value = "getBuyProportion")
 	public void getBuyProportion(String callback, String channelArray, Integer dateType, 
 		 String year, String startTime, String endTime, Integer orderNum, PrintWriter out) {
-		
-		validateParams(callback, channelArray, dateType,year,startTime,endTime,out);
 		
 		if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
 			startTime = null;
@@ -1389,53 +1445,78 @@
 	 * @param endTime   2018-12-01 
 	 * @param out
 	 */
-	@RequestMapping(value = "getHistoryNewUser")
-	public void getHistoryNewUser(String callback, Integer dateType, String year, String startTime,
-			String endTime, PrintWriter out) {
-		
-		if (dateType == null) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夋嫨鏄剧ず鏂瑰紡"));
+	@RequestMapping(value = "getNewUserCharts")
+	public void getNewUserCharts(String callback, Integer dateType, String year, String startTime,
+			String endTime,	PrintWriter out) {
+
+		String validateMsg = AdminUtils.validateParams(dateType, startTime, endTime);
+		if (validateMsg != null) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(validateMsg));
 			return;
 		}
-		
-		if (dateType == 1 && (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime))) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夋嫨鏃堕棿鍖洪棿"));
-			return;
-		}
-		
-		if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夌粨鏉熸棩鏈�"));
-			return;
-		}
-		
-		if (StringUtil.isNullOrEmpty(startTime) && !StringUtil.isNullOrEmpty(endTime)) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夎捣濮嬫棩鏈�"));
-			return;
-		}
-		
+
 		if (dateType != 1 && (!StringUtil.isNullOrEmpty(startTime) || !StringUtil.isNullOrEmpty(endTime))) {
 			startTime = null;
 			endTime = null;
 		}
-		
+
+		if (dateType == 1 && year != null) {
+			year = null; // 璁剧疆涓虹┖
+		} else if (dateType == 2) {
+			if (startTime != null)
+				startTime = 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;
+		}
+
 		try {
 
-			List<Object> resultList = userInfoCountService.countNewUserByDate(dateType, year, startTime, endTime);
+			Gson gson = new Gson();
+			Object objectDate = null;
+			List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
 
-			if (resultList == null) {
-				resultList = new ArrayList<Object>();
-			}
-				
+			JSONArray line_list = new JSONArray();
+
+			List<Map<String, Object>> list = userInfoCountService
+					.countNewUserByDate(dateType, year, startTime, endTime);
+
 			JSONObject innerList = new JSONObject();
-			innerList.put("name", "鏁伴噺");
-			innerList.put("data_list", resultList);
-			
-			JSONArray outList = new JSONArray();
-			outList.add(innerList);
-			
+			innerList.put("name", "鎬昏");
+
+			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", outList);
-			
+			if (objectDate != null) {
+				data.put("xAxis_list", gson.toJson(objectDate));
+			} else {
+				data.put("xAxis_list", gson.toJson(dateList));
+			}
+
+			data.put("line_list", line_list);
+
 			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
 
 		} catch (Exception e) {
@@ -1444,32 +1525,4 @@
 		}
 	}
 	
-	public void validateParams(String callback, String channelArray, Integer dateType, 
-			 String year, String startTime, String endTime, PrintWriter out) {
-
-		if (StringUtil.isNullOrEmpty(channelArray)) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夋嫨缁熻瀵瑰簲鍚嶇О"));
-			return;
-		}
-		
-		if (dateType == null) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夋嫨鎺掑垪鏂瑰紡"));
-			return;
-		}
-		
-		if (dateType == 1 && (StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime))) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夋嫨鏃堕棿鍖洪棿"));
-			return;
-		}
-		
-		if (!StringUtil.isNullOrEmpty(startTime) && StringUtil.isNullOrEmpty(endTime)) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夌粨鏉熸棩鏈�"));
-			return;
-		}
-		
-		if (StringUtil.isNullOrEmpty(startTime) && !StringUtil.isNullOrEmpty(endTime)) {
-			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇烽�夎捣濮嬫棩鏈�"));
-			return;
-		}
-	}
 }

--
Gitblit v1.8.0