From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 二月 2025 16:41:22 +0800
Subject: [PATCH] 淘宝转链接口更新

---
 fanli/src/main/java/com/yeshi/fanli/job/TaoLiJinJob.java |  354 ++++++++++++++++++++++++++++++++--------------------------
 1 files changed, 197 insertions(+), 157 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/job/TaoLiJinJob.java b/fanli/src/main/java/com/yeshi/fanli/job/TaoLiJinJob.java
index c1cbbf7..23366a7 100644
--- a/fanli/src/main/java/com/yeshi/fanli/job/TaoLiJinJob.java
+++ b/fanli/src/main/java/com/yeshi/fanli/job/TaoLiJinJob.java
@@ -1,157 +1,197 @@
-package com.yeshi.fanli.job;
-
-import java.math.BigDecimal;
-import java.util.Collections;
-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.taobao.ShareHotGoods;
-import com.yeshi.fanli.entity.taobao.TLJBuyGoods;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.fanli.entity.taobao.TaoKeAppInfo;
-import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
-import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
-import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
-import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinReportService;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.TaoBaoConstant;
-import com.yeshi.fanli.util.TimeUtil;
-import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
-
-@Component
-public class TaoLiJinJob {
-
-	@Resource
-	private UserTaoLiJinReportService userTaoLiJinReportService;
-
-	@Resource
-	private ShareHotGoodsService shareHotGoodsService;
-
-	@Resource
-	private TLJBuyGoodsService tljBuyGoodsService;
-
-	@Resource
-	private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
-
-	/**
-	 * 鏇存柊鎶ュ憡
-	 */
-	@Scheduled(cron = "0 0 1,10 * * ?")
-	public void insetDynamicInfo() {
-
-		if (!Constant.IS_TASK) {
-			return;
-		}
-
-		try {
-			userTaoLiJinReportService.needUpdateReport();
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-		}
-	}
-
-	/**
-	 * 閫�鍥炶秴杩�3澶╂棤棰嗗彇鐨勬窐绀奸噾
-	 */
-	@Scheduled(cron = "0 0 1 * * ?")
-	public void refundNotWin() {
-
-		if (!Constant.IS_TASK) {
-			return;
-		}
-
-		try {
-			userTaoLiJinReportService.refundNotWin();
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e);
-		}
-	}
-
-	/**
-	 * 姣忓ぉ鍑屾櫒杩�5鍒嗛挓楠岃瘉
-	 */
-	@Scheduled(cron = "0 2 0 * * ?")
-	public void updateShareTLJGoods() {
-		if (!Constant.IS_TASK)
-			return;
-		LogHelper.test("楠岃瘉鐖嗘鍟嗗搧搴撳晢鍝�");
-		String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
-		List<ShareHotGoods> list = shareHotGoodsService.listByDay(day, 15);
-		int count = 0;
-		for (int i = 0; i < list.size(); i++) {
-			if (count >= 10)
-				break;
-			boolean success = shareHotGoodsService.verifyCanCreateTLJ(list.get(i).getGoods().getAuctionId(),
-					new TaoKeAppInfo(TaoBaoConstant.TAOBAO_AUTH_APPKEY, TaoBaoConstant.TAOBAO_AUTH_APPSECRET,
-							TaoBaoConstant.TAOBAO_SPECIAL_PID_DEFAULT));
-			if (success) {
-				count++;
-			}
-		}
-	}
-
-	/**
-	 * 姣忓ぉ鍑屾櫒杩�3鍒嗛挓楠岃瘉
-	 */
-	@Scheduled(cron = "0 3 0 * * ?")
-	public void updateBuyTLJGoods() {
-		if (!Constant.IS_TASK)
-			return;
-		LogHelper.test("楠岃瘉鑷喘绔嬪噺鍟嗗搧");
-		String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
-		List<TLJBuyGoods> list = tljBuyGoodsService.listByDay(day, 15);
-		int count = 0;
-		for (int i = 0; i < list.size(); i++) {
-			if (count >= 10)
-				break;
-			boolean success = tljBuyGoodsService.verifyCanCreateTLJ(list.get(i).getGoods().getAuctionId());
-			if (success) {
-				count++;
-			}
-		}
-	}
-
-	/**
-	 * 姣忓ぉ鏅氫笂11鐐�50娣诲姞娣樼ぜ閲�
-	 */
-	@Scheduled(cron = "0 50 23 * * ? ")
-	public void autoAddTLJBuyGoods() {
-		if (!Constant.IS_TASK)
-			return;
-		String day = TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd");
-		List<TaoBaoGoodsBrief> list = tljBuyGoodsService.listPreGoods(1);
-		Collections.shuffle(list);
-		if (list.size() > 20)
-			list = list.subList(0, 20);
-		for (TaoBaoGoodsBrief goods : list) {
-			// 鑾峰彇鍟嗗搧璇︽儏
-			try {
-				goods = TaoKeApiUtil.searchGoodsDetail(goods.getAuctionId());
-			} catch (TaobaoGoodsDownException e) {
-				e.printStackTrace();
-			}
-			if (goods != null && goods.getCouponAmount() != null
-					&& goods.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {
-
-				if (TaoBaoUtil.getAfterUseCouplePrice(goods).multiply(goods.getTkRate())
-						.compareTo(new BigDecimal("143")) >= 0) {
-					goods = daTaoKeGoodsDetailService.filterTaoBaoGoods(goods);
-					int totalHongBaoCount = 2000 + (int) (Math.random() * 8000);
-					int leftHongBaoCount = 200 + (int) (Math.random() * 2000);
-					tljBuyGoodsService.addTLJBuyGoods(
-							new TLJBuyGoods(null, day, new Date(), goods, totalHongBaoCount, leftHongBaoCount),
-							TaoBaoConstant.ownBuyApp);
-				}
-			}
-		}
-	}
-
-}
+package com.yeshi.fanli.job;
+
+import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Random;
+
+import javax.annotation.Resource;
+
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import com.yeshi.fanli.entity.taobao.TLJBuyGoods;
+import com.yeshi.fanli.entity.taobao.TLJFreeBuyGoods;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
+import com.yeshi.common.entity.taobao.TaoKeAppInfo;
+import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsService;
+import com.yeshi.fanli.service.inter.taobao.TLJFreeBuyGoodsService;
+import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
+import com.yeshi.goods.facade.service.DaTaoKeGoodsDetailV2Service;
+import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinGiveRecordService;
+import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
+import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinReportService;
+import com.yeshi.fanli.util.Constant;
+import org.yeshi.utils.TimeUtil;
+import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
+
+@Component
+public class TaoLiJinJob {
+
+	@Resource
+	private UserTaoLiJinReportService userTaoLiJinReportService;
+
+	@Resource
+	private TLJBuyGoodsService tljBuyGoodsService;
+
+	@Resource
+	private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
+
+	@Resource
+	private TaoBaoUnionConfigService taoBaoUnionConfigService;
+
+	@Resource
+	private UserTaoLiJinGiveRecordService userTaoLiJinGiveRecordService;
+
+	@Resource
+	private UserTaoLiJinOriginService userTaoLiJinOriginService;
+
+	@Resource
+	private TLJFreeBuyGoodsService tljFreeBuyGoodsService;
+	
+
+
+	/**
+	 * 姣忓ぉ鍑屾櫒5鐐硅繃10鍒嗛挓楠岃瘉
+	 */
+	@Scheduled(cron = "0 10 5 * * ? ")
+	public void updateBuyTLJGoods() {
+		if (!Constant.IS_TASK)
+			return;
+		LogHelper.test("楠岃瘉鑷喘绔嬪噺鍟嗗搧");
+		String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
+		List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService
+				.getConfigByTypeCache(TaoBaoUnionConfig.TYPE_TLJ_BUY);
+		int totalCount = 0;
+		for (TaoBaoUnionConfig app : configList) {
+			List<TLJBuyGoods> list = tljBuyGoodsService.listByDay(app.getAppKey(), day, 15);// 鑾峰彇鏈�澶�15涓晢鍝�
+			int count = 0;
+			for (int i = 0; i < list.size(); i++) {
+				if (count >= 10)
+					break;
+				boolean success = tljBuyGoodsService.verifyCanCreateTLJ(list.get(i).getGoods().getAuctionId(),
+						new TaoKeAppInfo(app.getAppKey(), app.getAppSecret(), app.getDefaultPid()));
+				if (success) {
+					count++;
+				}
+			}
+			totalCount += count;
+		}
+		LogHelper.test("鑷喘绔嬪噺鍟嗗搧楠岃瘉閫氳繃鐨勬暟閲�:" + totalCount);
+	}
+
+	private void addTLJBuyGoods(List<TaoBaoGoodsBrief> list, String day) {
+		for (TaoBaoGoodsBrief goods : list) {
+			// 鑾峰彇鍟嗗搧璇︽儏
+			try {
+				goods = TaoKeApiUtil.searchGoodsDetail(goods.getAuctionId());
+			} catch (TaobaoGoodsDownException e) {
+				e.printStackTrace();
+			}
+			if (goods != null && goods.getCouponAmount() != null
+					&& goods.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {
+
+				// 娣樼ぜ閲戠殑閲戦浣嶄簬1-10鍧椾箣闂� 蹇呴』鏄ぉ鐚�
+				if (TaoBaoUtil.getCouponPrice(goods).multiply(goods.getTkRate())
+						.compareTo(new BigDecimal("143")) >= 0
+						&& TaoBaoUtil.getCouponPrice(goods).multiply(goods.getTkRate())
+								.compareTo(new BigDecimal("1430")) <= 0
+						&& goods.getUserType() == 1) {
+					goods = daTaoKeGoodsDetailV2Service.filterTaoBaoGoods(goods).getGoods();
+					int totalHongBaoCount = 2000 + (int) (Math.random() * 8000);
+					int leftHongBaoCount = 200 + (int) (Math.random() * 2000);
+					tljBuyGoodsService.addTLJBuyGoods(
+							new TLJBuyGoods(null, day, new Date(), goods, totalHongBaoCount, leftHongBaoCount));
+				}
+			}
+		}
+	}
+
+	/**
+	 * 姣忓ぉ鍑屾櫒5鐐硅繃1鍒嗗紑濮嬬埇鍙栧墿浣�9涓晢鍝�
+	 */
+	@Scheduled(cron = "0 1 5 * * ? ")
+	public void autoAddTLJBuyGoods2() {
+		// if (!Constant.IS_TASK)
+		// return;
+		LogHelper.test("鑷喘绔嬪噺寮�濮嬮�夊搧");
+		String day = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd");
+		// 閲嶈瘯3娆�
+		List<TaoBaoGoodsBrief> list = null;
+		try {
+			list = tljBuyGoodsService.listPreGoods(1);
+		} catch (Exception e) {
+		}
+		if (list == null || list.size() == 0)
+			try {
+				list = tljBuyGoodsService.listPreGoods(1);
+			} catch (Exception e) {
+			}
+		if (list == null || list.size() == 0)
+			try {
+				list = tljBuyGoodsService.listPreGoods(1);
+			} catch (Exception e) {
+			}
+
+		LogHelper.test("鑷喘绔嬪噺澶囬�夊晢鍝佹暟閲�:" + list.size());
+		Collections.shuffle(list);
+		List<TaoBaoUnionConfig> configList = taoBaoUnionConfigService
+				.getConfigByTypeCache(TaoBaoUnionConfig.TYPE_TLJ_BUY);
+
+		if (list.size() > 12 * configList.size())
+			list = list.subList(0, 12 * configList.size());
+		addTLJBuyGoods(list, day);
+	}
+
+	
+	/**
+	 * 姣忓ぉ鍑屾櫒23鐐硅繃1鍒嗗紑濮嬬埇鍙�
+	 */
+	@Scheduled(cron = "0 1 23 * * ? ")
+	public void autoAddTLJFreeBuyGoods() {
+		 if (!Constant.IS_TASK)
+			 return;
+		 
+		String day = TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24L, "yyyy-MM-dd");
+		LogHelper.test("鍏嶅崟鍟嗗搧寮�濮嬮�夊搧" + day);
+		
+		// 鏄惁宸查閫�
+		List<TLJFreeBuyGoods> listSelect = tljFreeBuyGoodsService.listByDay(day);
+		if (listSelect != null && listSelect.size() > 0)
+			return;
+		
+		int count = 0;
+		int maxCount = 15;
+		for (int page = 1; page <= 10; page ++) {
+			List<TaoBaoGoodsBrief> list = tljFreeBuyGoodsService.listPreGoods("", page);
+			if (list == null || list.size() == 0)
+				break;
+			
+			while (list.size() > 0) {
+				if (count >= maxCount)
+					break;
+				
+				Random random = new Random();
+				int n = random.nextInt(list.size());
+				TaoBaoGoodsBrief goods = list.get(n);
+				if (goods.getCouponAmount() != null && goods.getCouponAmount().compareTo(new BigDecimal(0)) > 0) {
+					BigDecimal couplePrice = TaoBaoUtil.getCouponPrice(goods);
+					if (couplePrice.compareTo(new BigDecimal(1.0)) >= 0 && couplePrice.compareTo(new BigDecimal(2.0)) <= 0) {
+						tljFreeBuyGoodsService.addGoods(new TLJFreeBuyGoods(day, goods));
+						count ++;
+					}
+				}
+				list.remove(n);
+			}
+			
+			if (count >= maxCount)
+				break;
+		}
+		
+	}
+}

--
Gitblit v1.8.0