From 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 09 五月 2020 21:41:27 +0800
Subject: [PATCH] 2.1需求

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/utils/AdminUtils.java |   61 ++++++++++++++----------------
 1 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/utils/AdminUtils.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/utils/AdminUtils.java
index 6dc70e7..09e46ee 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/utils/AdminUtils.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/utils/AdminUtils.java
@@ -5,13 +5,14 @@
 import java.util.List;
 import java.util.Map;
 
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
 import org.yeshi.utils.DateUtil;
 
 import com.google.gson.Gson;
+import com.yeshi.fanli.dto.ChartTDO;
 import com.yeshi.fanli.util.StringUtil;
+
+import net.sf.json.JSONArray;
+import net.sf.json.JSONObject;
 
 
 public class AdminUtils {
@@ -59,27 +60,28 @@
 			for (int i = 1; i <= 12; i++) {
 				dateList.add(i + ""); // 12涓湀
 			}
+		} else if (dateType == 3) {
+			for (int i = 2018; i <= 2030; i++) {
+				dateList.add(i + ""); // 10骞�
+			}
 		}
 		
 		return dateList;                   
 	}
 	
 	
-	public static Map<String, Object> yearsDataFactory(List<Map<String, Object>> list) {
+	public static Map<String, Object> yearsDataFactory(List<ChartTDO> list) {
 
 		List<Object> resultList = new ArrayList<Object>();
 		List<Object> listDate = new ArrayList<Object>();
 		
 		if (list != null && list.size() > 0) {
-			for (int i = 0; i < list.size(); i++) {
-				Map<String, Object> map = list.get(i);
-				Object showValue = map.get("showValue");
-				Object showDate = map.get("showDate");
-	
+			for (ChartTDO chart: list) {
+				String showDate = chart.getShowDate();
+				String showValue = chart.getShowValue();
 				if (showValue == null) {
-					showValue = 0;
+					showValue = "0";
 				}
-				
 				resultList.add(showValue);
 				listDate.add(showDate);
 			}
@@ -94,36 +96,31 @@
 
 	
 	
-	public static List<Object> dayOrMonthDataFactory(List<String> listDate , List<Map<String, Object>> list) throws Exception {
-
+	public static List<Object> dayOrMonthDataFactory(Integer dateType, List<String> listDate , 
+			List<ChartTDO> list) throws Exception {
 		List<Object> resultList = new ArrayList<Object>();
-		
 		if (list != null && list.size() > 0) {
 			for (int i = 0; i < listDate.size(); i++) {
-				Object showValue = null;
-				if (list != null && list.size() > 0) {
-					// 鏃ユ湡鍖归厤璧嬪��
-					for (int j = 0; j < list.size(); j++) {
-						Map<String, Object> map = list.get(j);
-						
-						String showDate = listDate.get(i);
-						Object reslutDate = map.get("showDate");
-						String month = reslutDate.toString();
-						
-						if (showDate.equalsIgnoreCase(month)) {
-							showValue = map.get("showValue");
-							break;
-						}
+				String showValue = null;
+				// 鏃ユ湡鍖归厤璧嬪��
+				for (ChartTDO chart: list) {
+					String showDate = listDate.get(i);
+					if (dateType == 2 && Integer.parseInt(showDate) < 10 ) {
+						showDate = "0" + showDate;
+					}
+					String reslutTime = chart.getShowDate();
+					if (showDate.equalsIgnoreCase(reslutTime)) {
+						showValue = chart.getShowValue();
+						break;
 					}
 				}
 				
 				if (showValue == null) {
-					showValue = 0;
+					showValue = "0";
 				}
 				resultList.add(showValue);
 			}
 		}
-		
 		return resultList;
 	}
 	
@@ -138,7 +135,7 @@
 	 * @throws Exception
 	 */
 	public static JSONObject chartDataFactory(Integer dateType, String year, String startTime, String endTime, 
-			List<Map<String, Object>> list) throws Exception{
+			List<ChartTDO> list) throws Exception{
 
 		Object objectDate = null;
 		List<String> dateList = getDateList(dateType, startTime, endTime, year);
@@ -150,7 +147,7 @@
 		innerList.put("name", "鎬昏");
 
 		if (dateType != 3) {
-			innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateList, list)));
+			innerList.put("data", gson.toJson(AdminUtils.dayOrMonthDataFactory(dateType, dateList, list)));
 		} else {
 			// 骞磋鍥�
 			Map<String, Object> map = yearsDataFactory(list);

--
Gitblit v1.8.0