From dc5be7d38446f70e6ff86df311119c32b41fe7f8 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 28 十一月 2020 16:37:05 +0800
Subject: [PATCH] 大淘客搜索接口升级

---
 fanli/src/main/java/com/yeshi/fanli/job/RedPackJob.java |   85 +++++++++++++++++++++++++++++++++++-------
 1 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/job/RedPackJob.java b/fanli/src/main/java/com/yeshi/fanli/job/RedPackJob.java
index 7151126..0504198 100644
--- a/fanli/src/main/java/com/yeshi/fanli/job/RedPackJob.java
+++ b/fanli/src/main/java/com/yeshi/fanli/job/RedPackJob.java
@@ -1,41 +1,96 @@
 package com.yeshi.fanli.job;
 
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
 import javax.annotation.Resource;
 
-import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
-import com.yeshi.fanli.entity.redpack.RedPackGiveRecord;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.yeshi.fanli.dto.user.PullNewRuleTerm;
 import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService;
-import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
+import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService;
+import com.yeshi.fanli.util.StringUtil;
 
 @Component
 public class RedPackJob {
 
 	@Resource
-	private RedPackGiveRecordService redPackGiveRecordService;
+	private RedPackWinInviteService redPackWinInviteService;
+	
+	@Resource
+	private RedPackConfigService redPackConfigService;
+	
+	
+	
+	@XxlJob("RedPackJob-arriveMoney")
+	public ReturnT<String> arriveMoney(String param) throws Exception {
+		arriveMoney();
+		return ReturnT.SUCCESS;
+	}
 	
 	/**
-	 * 姣忓ぉ涓�涓皬鏃舵洿鏂伴��鍥�
+	 * 绾㈠寘姣忔湀26鍒拌处
 	 */
-	@Scheduled(cron = "0 0 0/1 * * ? ")
-	public void overdue() {
-		if (!Constant.IS_TASK)
-			return;
-		
+	public void arriveMoney() {
 		try {
-			for (int i = 0; i < 100; i++) {
-				List<RedPackGiveRecord> overdueList = redPackGiveRecordService.overdueList(500);
-				if (overdueList == null || overdueList.size() == 0) {
+			String value = redPackConfigService.getValueByKey("win_redpack_term");
+			if (StringUtil.isNullOrEmpty(value)) {
+				return;
+			}
+			
+			Type type = new TypeToken<ArrayList<PullNewRuleTerm>>() {
+			}.getType();
+			List<PullNewRuleTerm> listRule = new Gson().fromJson(value, type);
+			if (listRule == null || listRule.size() == 0) {
+				return;
+			}
+			
+			int start = 0;
+			Date date = new Date();
+			while(true) {
+				// 涓婃湀瀛樺湪閭�璇风殑鐢ㄧ敤鎴穒d
+				List<Long> list = redPackWinInviteService.listWinUid(start, 1000);
+				if (list == null || list.size() == 0) {
 					break;
 				}
-				redPackGiveRecordService.overdue(overdueList);
+				
+				for (Long uid: list) {
+					// 缁熻涓婃湀閭�璇锋垚鍔熸暟閲�
+					long count = redPackWinInviteService.countLastMonthByUid(uid);
+					if (count == 0)
+						continue;
+					
+					BigDecimal money = null;
+					for (PullNewRuleTerm term: listRule) {
+						if (count >= term.getMin() && (term.getMax() != null && count <= term.getMax())) {
+							money = term.getMoney();
+						}
+					}
+					
+					if (money == null) {
+						LogHelper.test("绾㈠寘濂栧姳鏈尮閰嶅埌瑙勫垯count =" + count + " uid =" + uid);
+						continue;
+					}
+					
+					try {
+						redPackWinInviteService.arriveMoney(uid, money, date);
+					} catch (Exception e) {
+						LogHelper.errorDetailInfo(e);
+					}
+				}
 			}
 		} catch (Exception e) {
 			LogHelper.errorDetailInfo(e);
 		}
 	}
+	 
 }

--
Gitblit v1.8.0