From ee5c8055b1c0dd7c67a9025a76b10bd287c93d9a Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 15 四月 2020 09:52:27 +0800
Subject: [PATCH] 资金明细增加团队分红

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java |  132 +++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 129 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java
index e2f2fd1..a16da09 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/CountChartsAdminController.java
@@ -21,9 +21,11 @@
 import com.yeshi.fanli.entity.admin.count.CountOrderTrackRate;
 import com.yeshi.fanli.entity.admin.count.CountUserInfo;
 import com.yeshi.fanli.entity.admin.count.DailyCountCoupon;
+import com.yeshi.fanli.entity.admin.count.DailyCountMoments;
 import com.yeshi.fanli.entity.admin.count.DailyCountOrder;
 import com.yeshi.fanli.entity.admin.count.DailyCountUser;
 import com.yeshi.fanli.service.inter.count.DailyCountCouponService;
+import com.yeshi.fanli.service.inter.count.DailyCountMomentsService;
 import com.yeshi.fanli.service.inter.count.DailyCountOrderService;
 import com.yeshi.fanli.service.inter.count.DailyCountUserService;
 import com.yeshi.fanli.service.inter.count.UserInfoCountService;
@@ -53,6 +55,9 @@
 	
 	@Resource
 	private DailyCountOrderService dailyCountOrderService;
+	
+	@Resource
+	private DailyCountMomentsService dailyCountMomentsService;
 	
 	
 	private void verifyQueryData(String callback, Integer dateType, String year, String startTime, 
@@ -849,6 +854,9 @@
 			BigDecimal result = new BigDecimal(0);
 			
 			if (listData != null) {
+				 BigDecimal totalDay = new BigDecimal(0);
+				 BigDecimal totalValid = new BigDecimal(0);
+				
 				for (DailyCountUser history: listData) {
 					if (dateType == 1) {
 						String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
@@ -862,14 +870,30 @@
 							gernalTime = gernalTime.substring(1, 2);
 						}
 						if (gernalTime.equalsIgnoreCase(date)) {
-							result = MoneyBigDecimalUtil.add(result, history.getTotal());
+							if (!history.isRate()) {
+								result = MoneyBigDecimalUtil.add(result, history.getTotal());
+							} else {
+								totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
+								totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
+							}
 						}
 					} else if (dateType == 3) {
 						String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
 						if (gernalTime.equalsIgnoreCase(date)) {
-							result = MoneyBigDecimalUtil.add(result, history.getTotal());
+							if (!history.isRate()) {
+								result = MoneyBigDecimalUtil.add(result, history.getTotal());
+							} else {
+								totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
+								totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
+							}
 						}
 					}
+				}
+				
+				// 鍒ゆ柇鏄惁璁$畻姣斾緥
+				if ((dateType == 2 || dateType == 3) && totalDay.compareTo(BigDecimal.valueOf(0)) > 0){
+					result = MoneyBigDecimalUtil.div(totalValid, totalDay);
+					result = MoneyBigDecimalUtil.mul(result, BigDecimal.valueOf(100));
 				}
 			}
 			list.add(result);
@@ -879,7 +903,7 @@
 	
 	
 	/**
-	 * 鐢ㄦ埛鐩稿叧鍥捐〃鏁版嵁
+	 * 璁㈠崟鐩稿叧鍥捐〃鏁版嵁
 	 * @param callback
 	 * @param dateType
 	 * @param year
@@ -962,6 +986,9 @@
 			BigDecimal result = new BigDecimal(0);
 			
 			if (listData != null) {
+				 BigDecimal totalDay = new BigDecimal(0);
+				 BigDecimal totalValid = new BigDecimal(0);
+				 
 				for (DailyCountOrder history: listData) {
 					if (dateType == 1) {
 						String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
@@ -975,6 +1002,105 @@
 							gernalTime = gernalTime.substring(1, 2);
 						}
 						if (gernalTime.equalsIgnoreCase(date)) {
+							if (!history.isRate()) {
+								result = MoneyBigDecimalUtil.add(result, history.getTotal());
+							} else {
+								totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
+								totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
+							}
+						}
+					} else if (dateType == 3) {
+						String gernalTime = TimeUtil.getYearOnlyYYYY(history.getDay());
+						if (gernalTime.equalsIgnoreCase(date)) {
+							if (!history.isRate()) {
+								result = MoneyBigDecimalUtil.add(result, history.getTotal());
+							} else {
+								totalDay = MoneyBigDecimalUtil.add(totalDay, history.getTotalDay());
+								totalValid = MoneyBigDecimalUtil.add(totalValid, history.getTotalValid());
+							}
+						}
+					}
+				}
+				
+				// 鍒ゆ柇鏄惁璁$畻姣斾緥
+				if ((dateType == 2 || dateType == 3) && totalDay.compareTo(BigDecimal.valueOf(0)) > 0){
+					result = MoneyBigDecimalUtil.div(totalValid, totalDay);
+					result = MoneyBigDecimalUtil.mul(result, BigDecimal.valueOf(100));
+				}
+			}
+			list.add(result);
+		}
+		return list;
+	}
+	
+	
+	
+	@RequestMapping(value = "getMomentsCharts")
+	public void getMomentsCharts(String callback, Integer dateType, String year, String startTime, String endTime, 
+			String typeArray, PrintWriter out) {
+		try {
+			// 鏁版嵁楠岃瘉澶勭悊
+			verifyQueryData(callback, dateType, year, startTime, endTime, out);
+			
+			Date beginDate = getBeginDate(dateType, year, startTime);
+			Date endDate = getEndDate(dateType, year, endTime);
+			
+			Gson gson = new Gson();
+			List<String> dateList = AdminUtils.getDateList(dateType, startTime, endTime, year);
+			
+			// 娓犻亾
+			List<String> typelList = null;
+			if (typeArray != null && typeArray.trim().length() > 4) {
+				typelList = gson.fromJson(typeArray, new TypeToken<ArrayList<String>>() {}.getType());
+			}
+			
+			if (typelList == null || typelList.size() == 0) {
+				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("浼犻�掔被鍨嬮敊璇�"));
+				return;
+			}
+			
+			
+			JSONArray line_list = new JSONArray();
+			for (String type: typelList) {
+				List<DailyCountMoments> listData = dailyCountMomentsService.getDailyCountList(type, beginDate, endDate);
+				// 澶勭悊鏁版嵁
+				List<Object> list = machineDailyCountMoments(dateList, dateType, listData);
+				
+				JSONObject innerList = new JSONObject();
+				innerList.put("name", dailyCountMomentsService.getTypeEnumDesc(type));
+				innerList.put("data", gson.toJson(list));
+				line_list.add(innerList);
+			}
+			
+			JSONObject data = new JSONObject();
+			data.put("line_list", line_list);
+			data.put("xAxis_list", gson.toJson(dateList));
+			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
+		} catch (Exception e) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("绯荤粺寮傚父"));
+			e.printStackTrace();
+		}
+	}
+	
+	
+	private List<Object> machineDailyCountMoments(List<String> dateList, Integer dateType, List<DailyCountMoments> listData) {
+		List<Object> list = new ArrayList<>();
+		for (String date: dateList) {
+			BigDecimal result = new BigDecimal(0);
+			
+			if (listData != null) {
+				for (DailyCountMoments history: listData) {
+					if (dateType == 1) {
+						String gernalTime = TimeUtil.getGernalTime(history.getDay().getTime());
+						if (gernalTime.equalsIgnoreCase(date)) {
+							result = MoneyBigDecimalUtil.add(result, history.getTotal());
+						}
+					} else if (dateType == 2){
+						String gernalTime = TimeUtil.getMonthOnlyMM(history.getDay());
+						if(gernalTime.startsWith("0")) {
+							gernalTime = gernalTime.substring(1, 2);
+						}
+						if (gernalTime.equalsIgnoreCase(date)) {
 							result = MoneyBigDecimalUtil.add(result, history.getTotal());
 						}
 					} else if (dateType == 3) {

--
Gitblit v1.8.0