From 28cf328a098334b51a3e9d2d56f983fb8c862211 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 23 五月 2020 09:54:38 +0800
Subject: [PATCH] 足迹、收藏订单兼容新需求

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountUserServiceImpl.java |   94 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 67 insertions(+), 27 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountUserServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountUserServiceImpl.java
index 945b907..6e6eaf8 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountUserServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/count/DailyCountUserServiceImpl.java
@@ -1,6 +1,7 @@
 package com.yeshi.fanli.service.impl.count;
 
 import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -10,7 +11,6 @@
 import org.yeshi.utils.DateUtil;
 
 import com.yeshi.fanli.dao.user.count.DailyCountUserDao;
-import com.yeshi.fanli.dto.order.CountOrderDTO;
 import com.yeshi.fanli.entity.admin.count.DailyCountUser;
 import com.yeshi.fanli.entity.admin.count.DailyCountUser.DailyCountUserEnum;
 import com.yeshi.fanli.entity.bus.user.Extract;
@@ -118,7 +118,8 @@
 	 * @param typeEnum
 	 * @throws Exception
 	 */
-	private void initData(DailyCountUserEnum typeEnum) throws Exception {
+	@Override
+	public void initData(DailyCountUserEnum typeEnum) throws Exception {
 		Date lastDate = null;
 		DailyCountUser lastRecord = dailyCountUserDao.getMaxDate(typeEnum);
 		if (lastRecord != null) {
@@ -126,7 +127,11 @@
 		} else {
 			lastDate = TimeUtil.parse("2017-05-06");
 		}
-
+		long min = DateUtil.dateDiffMin(lastDate, new Date());
+		if (min <= 10) { // 10鍒嗛挓浠ュ唴涓嶇粺璁�
+			return;
+		}
+		
 		Date today = new Date();
 		int betweenDays = DateUtil.daysBetween2(lastDate, today);
 		for (int i = 0; i <= betweenDays; i++) {
@@ -174,12 +179,11 @@
 		ChannelEnum[] channels = ChannelEnum.values();
 		for (int i = 0; i < channels.length; i++) {
 			Long count = userInfoRegisterService.countByChannelAndDay(channels[i].getVlaue(), preDay);
-			BigDecimal total = new BigDecimal(0);
-			if (count != null) {
-				total = new BigDecimal(total.toString());
+			if (count == null) {
+				count = 0L;
 			}
 			DailyCountUser obj = new DailyCountUser();
-			obj.setTotal(total);
+			obj.setTotal(BigDecimal.valueOf(count));
 			obj.setType(typeEnum);
 			obj.setChannel(channels[i].name());
 			obj.setUpdateDate(new Date());
@@ -197,25 +201,29 @@
 	 */
 	private void addNewUserDownOrderDay(String preDay, DailyCountUserEnum typeEnum) throws Exception {
 		// 缁熻褰撴棩鏈夋晥璁㈠崟
-		List<CountOrderDTO> listOrder = commonOrderCountService.countValidOrderByDay(preDay);
+		List<Long> listOrder = commonOrderCountService.getUidByValidOrderByDay(preDay);
+		
+		// 鏌ヨ褰撴棩鏂版敞鍐岀敤鎴�
+		List<UserInfoRegister> listRegister = userInfoRegisterService.listByDay(preDay);
 		
 		ChannelEnum[] channels = ChannelEnum.values();
 		for (int i = 0; i < channels.length; i++) {
+			long totalDay = 0;
+			long totalValid = 0;
+			String channelName = channels[i].getVlaue();
 			
-			long totalUser = 0;
-			long totalUserDown = 0;
-			if (listOrder != null && listOrder.size() > 0) {
-				// 鏌ヨ璇ユ笭閬撳綋鏃ユ敞鍐岀敤鎴�
-				List<UserInfoRegister> listRegister = userInfoRegisterService.listByChannelAndDay(channels[i].getVlaue(), preDay);
-				if (listRegister != null && listRegister.size() > 0) {
-					totalUser = listRegister.size();
-					
-					// 寰幆缁熻鏄惁瀛樺湪鐢ㄦ埛涓嬪崟
-					for (UserInfoRegister userInfoRegister: listRegister) {
-						Long id = userInfoRegister.getId();
-						for (CountOrderDTO dto: listOrder) {
-							if (dto.getUid() != null && dto.getUid().longValue() == id.longValue()) {
-								totalUserDown ++;
+			if (listOrder != null && listOrder.size() > 0 && listRegister != null && listRegister.size() > 0) {
+				for (UserInfoRegister register: listRegister) {
+					String channel = register.getChannel();
+					if (channelName.equalsIgnoreCase(channel)) {
+						// 褰撴棩娓犻亾鐢ㄦ埛
+						totalDay ++ ;
+						
+						Long id = register.getId();
+						// 鍒ゆ柇褰撳墠鐢ㄦ埛鏄惁浠婃棩涓嬪崟
+						for (Long uid: listOrder) {
+							if (uid.longValue() == id.longValue()) {
+								totalValid ++;
 								break;
 							}
 						}
@@ -225,13 +233,17 @@
 				
 			// 璁$畻姣斾緥锛� 涓嬪崟鐢ㄦ埛鏁�/鏂板鐢ㄦ埛鏁�
 			BigDecimal total = new BigDecimal(0);
-			if (totalUser > 0 && totalUserDown > 0) {
-				total = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalUserDown),BigDecimal.valueOf(totalUser));
+			if (totalDay > 0 && totalValid > 0) {
+				total = MoneyBigDecimalUtil.div(BigDecimal.valueOf(totalValid),BigDecimal.valueOf(totalDay));
 				total = MoneyBigDecimalUtil.mul(total, BigDecimal.valueOf(100));
 			}	
 				
 			DailyCountUser obj = new DailyCountUser();
 			obj.setTotal(total);
+			obj.setRate(true);
+			obj.setTotalDay(BigDecimal.valueOf(totalDay));
+			obj.setTotalValid(BigDecimal.valueOf(totalValid));
+			
 			obj.setType(typeEnum);
 			obj.setChannel(channels[i].name());
 			obj.setUpdateDate(new Date());
@@ -257,20 +269,42 @@
 			long totalUser = 0;
 			long totalWeek = 0;
 			long totalWeek3 = 0;
+			
+			List<Long> listUid = new ArrayList<Long>();
+			
 			// 鏌ヨ浠婃棩鏂板鐢ㄦ埛
 			List<UserInfoRegister> list = userInfoRegisterService.listByChannelAndDay(channels[i].getVlaue(), preDay);
+			
+			
 			if (list != null && list.size() > 0) {
 				totalUser = list.size();
 				for (UserInfoRegister user : list) {
-					Integer total = commonOrderCountService.countOderByUidAndDate(limitDay, user.getId());
-					if (total != null && total > 0) {
-						totalWeek ++;
+					listUid.add(user.getId());
+				}
+			}
+			
+			if (listUid.size() > 0) {
+				List<Long> listUidDown = commonOrderCountService.getDownOrderUserByListUidAndDate(limitDay, listUid);
+				if (listUidDown != null && listUidDown.size() > 0) {
+					for (Long uid: listUid) {
+						int total = 0;
+						for (Long id: listUidDown) {
+							if (uid.longValue() == id.longValue()) {
+								total ++;
+							}
+						}
+						
+						if (total > 0) {
+							totalWeek ++;
+						}
+						
 						if (total >= 3) {
 							totalWeek3 ++;
 						}
 					}
 				}
 			}
+			
 			
 			// 璁$畻姣斾緥锛氬綋鍛� 涓嬪崟鐢ㄦ埛鏁�/鏂板鐢ㄦ埛鏁�
 			BigDecimal total = new BigDecimal(0);
@@ -279,6 +313,9 @@
 				total = MoneyBigDecimalUtil.mul(total, BigDecimal.valueOf(100));
 			}	
 			DailyCountUser obj = new DailyCountUser();
+			obj.setRate(true);
+			obj.setTotalDay(BigDecimal.valueOf(totalUser));
+			obj.setTotalValid(BigDecimal.valueOf(totalWeek));
 			obj.setTotal(total);
 			obj.setType(DailyCountUserEnum.newUserDownOrderWeek);
 			obj.setChannel(channels[i].name());
@@ -295,6 +332,9 @@
 				total3 = MoneyBigDecimalUtil.mul(total3, BigDecimal.valueOf(100));
 			}	
 			DailyCountUser obj3 = new DailyCountUser();
+			obj3.setRate(true);
+			obj3.setTotalDay(BigDecimal.valueOf(totalUser));
+			obj3.setTotalValid(BigDecimal.valueOf(totalWeek3));
 			obj3.setTotal(total3);
 			obj3.setType(DailyCountUserEnum.newUserDownOrderWeek3);
 			obj3.setChannel(channels[i].name());

--
Gitblit v1.8.0