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/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java |  884 ++++++++++++++++++++++++++++++----------------------------
 1 files changed, 462 insertions(+), 422 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java
index cdad78e..722ddb1 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/taobao/dataoke/DaTaoKeGoodsDetailV2ServiceImpl.java
@@ -1,422 +1,462 @@
-package com.yeshi.fanli.service.impl.taobao.dataoke;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.scheduling.annotation.Async;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.yeshi.fanli.dao.goods.taobao.dataoke.DaTaoKeGoodsDetailV2Dao;
-import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
-import com.yeshi.fanli.dto.dataoke.DingDongQiangDTO;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
-import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
-import com.yeshi.fanli.log.LogHelper;
-import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
-import com.yeshi.fanli.util.RedisManager;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.TimeUtil;
-import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
-import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
-import com.yeshi.fanli.util.taobao.TaoBaoUtil;
-
-@Service
-public class DaTaoKeGoodsDetailV2ServiceImpl implements DaTaoKeGoodsDetailV2Service {
-	@Resource
-	private DaTaoKeGoodsDetailV2Dao daTaoKeGoodsDetailV2Dao;
-
-	@Resource
-	private RedisManager redisManager;
-
-	@Override
-	public void startSyncGoods() {
-		LogHelper.test("澶ф窐瀹㈠悓姝ュ紑濮�");
-
-		int totalCount = 0;
-		try {
-			DaTaoKeGoodsResult result = DaTaoKeApiUtil.listAll("1");
-			int page = 0;
-
-			while (result.getGoodsList() != null && result.getGoodsList().size() > 0) {
-				System.out.println(page++);
-				totalCount += result.getGoodsList().size();
-				for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
-					try {
-						daTaoKeGoodsDetailV2Dao.saveWithCommision(v2);
-					} catch (Exception e) {
-					}
-				}
-
-				try {
-					result = DaTaoKeApiUtil.listAll(result.getPageId());
-				} catch (Exception e) {
-					result = DaTaoKeApiUtil.listAll(result.getPageId());
-				}
-
-				try {
-					Thread.sleep(10);
-				} catch (InterruptedException e) {
-					e.printStackTrace();
-				}
-			}
-		} catch (Exception e) {
-			LogHelper.errorDetailInfo(e, "澶ф窐瀹㈠叏閲忔暟鎹嚭閿�", "");
-		} finally {
-			LogHelper.test("澶ф窐瀹㈡柊鐗堝晢鍝佸悓姝ユ暟閲�:" + totalCount);
-		}
-	}
-
-	@Override
-	public void updateData() {
-		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getUpdateGoodsList("1", null, null);
-		while (result.getGoodsList() != null && result.getGoodsList().size() > 0) {
-			for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
-				v2.setUpdateTime(new Date());
-				daTaoKeGoodsDetailV2Dao.updateSelective(v2);
-			}
-			try {
-				Thread.sleep(100);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			result = DaTaoKeApiUtil.getUpdateGoodsList(result.getPageId(), null, null);
-		}
-	}
-
-	@Override
-	public void deleteInvalid() {
-		String startTime = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd 00:00:00");
-
-		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getInvalidGoodsList(null, startTime, null);
-		while (result.getGoodsList() != null && result.getGoodsList().size() > 0) {
-			for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
-				v2.setUpdateTime(new Date());
-				daTaoKeGoodsDetailV2Dao.delete(v2.getId());
-			}
-			result = DaTaoKeApiUtil.getInvalidGoodsList(result.getPageId(), startTime, null);
-			System.out.println(result);
-			try {
-				Thread.sleep(200);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-	}
-
-	@Override
-	public void updateNewGoods() {
-		String startTime = null;
-		DaTaoKeDetailV2 latest = daTaoKeGoodsDetailV2Dao.selectLatest();
-		if (latest != null) {
-			startTime = TimeUtil.getGernalTime(latest.getCreateTime().getTime(), "yyyy-MM-dd HH:mm:ss");
-		}
-		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getNewGoodsList(null, startTime, null);
-		while (!StringUtil.isNullOrEmpty(result.getPageId())) {
-			for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
-				v2.setUpdateTime(new Date());
-				daTaoKeGoodsDetailV2Dao.saveWithCommision(v2);
-			}
-			result = DaTaoKeApiUtil.getNewGoodsList(result.getPageId(), startTime, null);
-			try {
-				Thread.sleep(200);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-	}
-
-	@Transactional
-	private void addGoodsList(List<DaTaoKeDetailV2> goodsList) {
-		for (DaTaoKeDetailV2 goods : goodsList) {
-			goods.setUpdateTime(new Date());
-			daTaoKeGoodsDetailV2Dao.saveWithCommision(goods);
-		}
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> listByGoodsIds(List<Long> goodsIdList) {
-		if (goodsIdList == null || goodsIdList.size() == 0)
-			return null;
-		List<DaTaoKeDetailV2> goodsList = daTaoKeGoodsDetailV2Dao.listByGoodsIds(goodsIdList);
-		return goodsList;
-	}
-
-	@Override
-	public List<TaoBaoGoodsBrief> filterTaoBaoGoods(List<TaoBaoGoodsBrief> goodsList) {
-		List<Long> goodsIdList = new ArrayList<>();
-		for (TaoBaoGoodsBrief goods : goodsList)
-			goodsIdList.add(goods.getAuctionId());
-
-		List<DaTaoKeDetailV2> dtList = listByGoodsIds(goodsIdList);
-
-		Map<Long, DaTaoKeDetailV2> map = new HashMap<>();
-		for (DaTaoKeDetailV2 goods : dtList)
-			map.put(goods.getGoodsId(), goods);
-		for (TaoBaoGoodsBrief goods : goodsList) {
-			DaTaoKeDetailV2 detail = map.get(goods.getAuctionId());
-			goods = DaTaoKeUtil.filterTaoBaoGoods(goods, detail);
-		}
-		return goodsList;
-	}
-
-	@Override
-	public TaoBaoGoodsBrief filterTaoBaoGoods(TaoBaoGoodsBrief goods) {
-		List<Long> goodsIdList = new ArrayList<>();
-		goodsIdList.add(goods.getAuctionId());
-
-		List<DaTaoKeDetailV2> daTaoKeList = listByGoodsIds(goodsIdList);
-		if (daTaoKeList == null || daTaoKeList.size() == 0)
-			return goods;
-
-		// 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
-		goods = DaTaoKeUtil.filterTaoBaoGoods(goods, daTaoKeList.get(0));
-
-		return goods;
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> listByIds(List<Long> idsList) {
-		return daTaoKeGoodsDetailV2Dao.listByIds(idsList);
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> listByDtitle(String dtitle) {
-
-		return daTaoKeGoodsDetailV2Dao.listByDtitle(dtitle.trim());
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> listSearchByTitleWithCid(String title, Long cid, int page, int pageSize) {
-		return daTaoKeGoodsDetailV2Dao.listSearchByTitleWithCid(title, (cid == null || cid == 0 ? null : cid),
-				(page - 1) * pageSize, pageSize);
-	}
-
-	@Override
-	public Long countSearchByTitleWithCid(String title, Long cid) {
-		return daTaoKeGoodsDetailV2Dao.countSearchByTitleWithCid(title, (cid == null || cid == 0 ? null : cid));
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> getGoodsNotInList(Long cid, List<Long> listId, int count) {
-		return daTaoKeGoodsDetailV2Dao.getGoodsNotInList(cid, listId, count);
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> listPreShareHotGoods(int page, BigDecimal minCommission) {
-		Map<Long, DaTaoKeDetailV2> map = new HashMap<>();
-		List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods((page - 1) * 100, 100, "hotPush",
-				minCommission);
-		System.out.println(list);
-		for (DaTaoKeDetailV2 v2 : list) {
-			map.put(v2.getId(), v2);
-		}
-
-		List<DaTaoKeDetailV2> finalList = new ArrayList<>();
-		for (Iterator<Long> its = map.keySet().iterator(); its.hasNext();) {
-			DaTaoKeDetailV2 v2 = map.get(its.next());
-			Date time = new Date(TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"));
-			Date targetTime = new Date(TimeUtil.convertToTimeTemp(
-					TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2L, "yyyy-MM-dd"),
-					"yyyy-MM-dd") - 1000L);
-			if (time.getTime() >= targetTime.getTime())
-				finalList.add(v2);
-		}
-
-		Comparator<DaTaoKeDetailV2> cm = new Comparator<DaTaoKeDetailV2>() {
-			@Override
-			public int compare(DaTaoKeDetailV2 o1, DaTaoKeDetailV2 o2) {
-				return o1.getActualPrice().compareTo(o2.getActualPrice());
-			}
-		};
-		Collections.sort(finalList, cm);
-		return finalList;
-	}
-
-	private boolean canAddToTLJBuyGoods(DaTaoKeDetailV2 v2) {
-		return TaoBaoUtil.canAddToTLJBuyGoods(TaoBaoUtil.convert(v2));
-	}
-
-	@Override
-	public List<DaTaoKeDetailV2> listPreTLJBuyGoods(int page) {
-		if (page == 1) {
-			List<DaTaoKeDetailV2> listPreGoodsList = new ArrayList<>();
-			// 鐑攢姒�
-			DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_HOT, null);
-			if (result != null && result.getGoodsList() != null)
-				listPreGoodsList.addAll(result.getGoodsList());
-			// 澶嶈喘姒�
-			result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_REBUY, null);
-			if (result != null && result.getGoodsList() != null)
-				listPreGoodsList.addAll(result.getGoodsList());
-			// 缁煎悎鎼滅储
-			try {
-				result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
-				if (result == null)
-					throw new Exception();
-			} catch (Exception e) {// 寮傚父閲嶅涓�娆�
-				result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
-			}
-
-			if (result != null && result.getGoodsList() != null)
-				listPreGoodsList.addAll(result.getGoodsList());
-
-			List<DaTaoKeDetailV2> goodsList = new ArrayList<>();
-			for (DaTaoKeDetailV2 v2 : listPreGoodsList) {
-				if (canAddToTLJBuyGoods(v2)) {
-					Date time = new Date(TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"));
-
-					Date targetTime = new Date(TimeUtil
-							.convertToTimeTemp(TimeUtil.getGernalTime(
-									System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2L, "yyyy-MM-dd"), "yyyy-MM-dd")
-							- 1000L);
-					// 濡傛灉鏄噷鏅ㄩ�夋嫨鐨�
-					if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 12) {// 涓婂崍閫夋嫨鐨勮绠椾负褰撳ぉ鐨�
-						targetTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(
-								System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 1L, "yyyy-MM-dd"), "yyyy-MM-dd")
-								- 1000L);
-					}
-					if (time.getTime() >= targetTime.getTime())
-						goodsList.add(v2);
-				}
-			}
-
-			// 鍘婚噸
-			Map<Long, DaTaoKeDetailV2> goodsMap = new HashMap<>();
-			for (DaTaoKeDetailV2 v2 : goodsList) {
-				goodsMap.put(v2.getGoodsId(), v2);
-			}
-			goodsList.clear();
-			for (Iterator<Long> its = goodsMap.keySet().iterator(); its.hasNext();) {
-				goodsList.add(goodsMap.get(its.next()));
-			}
-			Comparator<DaTaoKeDetailV2> cm = new Comparator<DaTaoKeDetailV2>() {
-
-				@Override
-				public int compare(DaTaoKeDetailV2 o1, DaTaoKeDetailV2 o2) {
-					return o1.getActualPrice().compareTo(o2.getActualPrice());
-				}
-			};
-			Collections.sort(goodsList, cm);
-			return goodsList;
-		} else
-			return new ArrayList<>();
-	}
-
-	@Override
-	public void deleteOutOfDate(Date minTime) {
-		daTaoKeGoodsDetailV2Dao.listAndRemoveByMinUpdateTime(minTime, 0, 3000);
-	}
-
-	@Override
-	public long countByMinUpdateTime(Date minTime) {
-		return daTaoKeGoodsDetailV2Dao.countByMinUpdateTime(minTime);
-	}
-
-	@Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData'")
-	@Override
-	public List<DingDongQiangDTO> getDingDongQiangData() {
-		List<DingDongQiangDTO> list = null;
-		int count = 0;
-		while ((list == null || list.size() == 0) && count < 3) {
-			count++;
-			list = DaTaoKeUtil.getDingDongQiang();
-		}
-		if (list == null)
-			return null;
-		return list;
-	}
-
-	@Async
-	private void updateGoods(Long id) {
-		DaTaoKeDetailV2 v2 = DaTaoKeApiUtil.getGoodsDetail(id);
-		if (v2 != null)
-			daTaoKeGoodsDetailV2Dao.save(v2);
-	}
-
-	private List<DaTaoKeDetailV2> getDefaultDingDongQiang() {
-		// 鎸夋洿鏂版椂闂村姞
-		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_TIME, null);
-		if (result != null && result.getGoodsList().size() > 0) {
-			List<DaTaoKeDetailV2> finalList = new ArrayList<>();
-			Collections.shuffle(result.getGoodsList());
-			finalList.addAll(result.getGoodsList().subList(0,
-					result.getGoodsList().size() > 8 ? 8 : result.getGoodsList().size()));
-			for (DaTaoKeDetailV2 detail : finalList) {
-				detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
-				if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
-					detail.setCouponReceiveNum(detail.getCouponTotalNum());
-			}
-			return finalList;
-		}
-		return null;
-	}
-
-	@Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData-'+#time")
-	@Override
-	public List<DaTaoKeDetailV2> getDingDongQiangData(String time) {
-		List<DingDongQiangDTO> list = getDingDongQiangData();
-		if (list == null || list.size() == 0) {
-			return getDefaultDingDongQiang();
-		}
-
-		Map<String, DingDongQiangDTO> map = new HashMap<>();
-		for (DingDongQiangDTO dto : list)
-			map.put(dto.getTime(), dto);
-
-		DingDongQiangDTO dto = map.get(time);
-		if (dto != null) {
-			List<Long> idList = new ArrayList<>();
-			for (DaTaoKeDetailV2 td : dto.getGoodsList())
-				idList.add(td.getId());
-			List<DaTaoKeDetailV2> finalList = listByIds(idList);
-			if (finalList.size() != idList.size()) {
-				for (Long id : idList)
-					updateGoods(id);
-				finalList = listByIds(idList);
-			}
-
-			// 濡傛灉鍟嗗搧鏁板皬浜�4锛岄渶瑕佸啀鍔犲晢鍝�
-			if (finalList == null || finalList.size() <= 3) {
-				// 鎸夋洿鏂版椂闂村姞
-				List<DaTaoKeDetailV2> latestList = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods(0, 50, "updateTime",
-						new BigDecimal("0.5"));
-				if (latestList != null && latestList.size() > 0) {
-					Collections.shuffle(latestList);
-					finalList.addAll(latestList.subList(0, latestList.size() > 8 ? 8 : latestList.size()));
-				}
-			}
-
-			for (DaTaoKeDetailV2 detail : finalList) {
-				detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
-				if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
-					detail.setCouponReceiveNum(detail.getCouponTotalNum());
-			}
-			return finalList;
-		} else {
-			return getDefaultDingDongQiang();
-		}
-	}
-
-	@Override
-	public List<String> getDingDongQiangTime() {
-		List<DingDongQiangDTO> list = getDingDongQiangData();
-		List<String> dateList = new ArrayList<>();
-		for (DingDongQiangDTO dto : list) {
-			dateList.add(dto.getTime());
-		}
-		return dateList;
-	}
-
-}
+package com.yeshi.fanli.service.impl.taobao.dataoke;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.yeshi.fanli.dao.goods.taobao.dataoke.DaTaoKeGoodsDetailV2Dao;
+import com.yeshi.goods.facade.dto.taobao.dataoke.DaTaoKeGoodsResult;
+import com.yeshi.goods.facade.dto.taobao.dataoke.DingDongQiangDTO;
+import com.yeshi.goods.facade.dto.taobao.dataoke.DaTaoKeFilterResult;
+import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.goods.facade.service.DaTaoKeGoodsDetailV2Service;
+import com.yeshi.fanli.util.RedisManager;
+import com.yeshi.fanli.util.StringUtil;
+import org.yeshi.utils.TimeUtil;
+import com.yeshi.goods.facade.utils.taobao.DaTaoKeApiUtil;
+import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
+import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+
+@Service
+public class DaTaoKeGoodsDetailV2ServiceImpl implements DaTaoKeGoodsDetailV2Service {
+	@Resource
+	private DaTaoKeGoodsDetailV2Dao daTaoKeGoodsDetailV2Dao;
+
+	@Resource
+	private RedisManager redisManager;
+
+	@Override
+	public void startSyncGoods() {
+		LogHelper.test("澶ф窐瀹㈠悓姝ュ紑濮�");
+
+		int totalCount = 0;
+		try {
+			DaTaoKeGoodsResult result = DaTaoKeApiUtil.listAll("1");
+			int page = 0;
+
+			while (result.getGoodsList() != null && result.getGoodsList().size() > 0) {
+				System.out.println(page++);
+				totalCount += result.getGoodsList().size();
+				for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
+					try {
+						daTaoKeGoodsDetailV2Dao.saveWithCommision(v2);
+					} catch (Exception e) {
+					}
+				}
+
+				try {
+					result = DaTaoKeApiUtil.listAll(result.getPageId());
+				} catch (Exception e) {
+					result = DaTaoKeApiUtil.listAll(result.getPageId());
+				}
+
+				try {
+					Thread.sleep(10);
+				} catch (InterruptedException e) {
+					e.printStackTrace();
+				}
+			}
+		} catch (Exception e) {
+			LogHelper.errorDetailInfo(e, "澶ф窐瀹㈠叏閲忔暟鎹嚭閿�", "");
+		} finally {
+			LogHelper.test("澶ф窐瀹㈡柊鐗堝晢鍝佸悓姝ユ暟閲�:" + totalCount);
+		}
+	}
+
+	@Override
+	public void updateData() {
+		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getUpdateGoodsList("1", null, null);
+		while (result.getGoodsList() != null && result.getGoodsList().size() > 0) {
+			for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
+				v2.setUpdateTime(new Date());
+				daTaoKeGoodsDetailV2Dao.updateSelective(v2);
+			}
+			try {
+				Thread.sleep(100);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			result = DaTaoKeApiUtil.getUpdateGoodsList(result.getPageId(), null, null);
+		}
+	}
+
+	@Override
+	public void deleteInvalid() {
+		String startTime = TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd 00:00:00");
+
+		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getInvalidGoodsList(null, startTime, null);
+		while (result.getGoodsList() != null && result.getGoodsList().size() > 0) {
+			for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
+				v2.setUpdateTime(new Date());
+				daTaoKeGoodsDetailV2Dao.delete(v2.getId());
+			}
+			result = DaTaoKeApiUtil.getInvalidGoodsList(result.getPageId(), startTime, null);
+			System.out.println(result);
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	@Override
+	public void updateNewGoods() {
+		String startTime = null;
+		DaTaoKeDetailV2 latest = daTaoKeGoodsDetailV2Dao.selectLatest();
+		if (latest != null) {
+			startTime = TimeUtil.getGernalTime(latest.getCreateTime().getTime(), "yyyy-MM-dd HH:mm:ss");
+		}
+		DaTaoKeGoodsResult result = DaTaoKeApiUtil.getNewGoodsList(null, startTime, null);
+		while (!StringUtil.isNullOrEmpty(result.getPageId())) {
+			for (DaTaoKeDetailV2 v2 : result.getGoodsList()) {
+				v2.setUpdateTime(new Date());
+				daTaoKeGoodsDetailV2Dao.saveWithCommision(v2);
+			}
+			result = DaTaoKeApiUtil.getNewGoodsList(result.getPageId(), startTime, null);
+			try {
+				Thread.sleep(200);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+	private void addGoodsList(List<DaTaoKeDetailV2> goodsList) {
+		for (DaTaoKeDetailV2 goods : goodsList) {
+			goods.setUpdateTime(new Date());
+			daTaoKeGoodsDetailV2Dao.saveWithCommision(goods);
+		}
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listByGoodsIds(List<String> goodsIdList) {
+		if (goodsIdList == null || goodsIdList.size() == 0)
+			return null;
+		List<DaTaoKeDetailV2> goodsList = daTaoKeGoodsDetailV2Dao.listByGoodsIds(goodsIdList);
+		return goodsList;
+	}
+
+	@Override
+	public List<TaoBaoGoodsBrief> filterTaoBaoGoods(List<TaoBaoGoodsBrief> goodsList) {
+		List<String> goodsIdList = new ArrayList<>();
+		for (TaoBaoGoodsBrief goods : goodsList)
+			goodsIdList.add(goods.getAuctionId());
+
+		List<DaTaoKeDetailV2> dtList = null;
+
+		try {
+			dtList = listByGoodsIds(goodsIdList);
+		} catch (Exception e) {
+
+		}
+		Map<String, DaTaoKeDetailV2> map = new HashMap<>();
+		if (dtList != null)
+			for (DaTaoKeDetailV2 goods : dtList)
+				map.put(goods.getGoodsId(), goods);
+		for (TaoBaoGoodsBrief goods : goodsList) {
+			DaTaoKeDetailV2 detail = map.get(goods.getAuctionId());
+			goods = DaTaoKeUtil.filterTaoBaoGoods(goods, detail);
+		}
+		return goodsList;
+	}
+
+
+	@Override
+	public List<DaTaoKeDetailV2> listByIds(List<Long> idsList) {
+		return daTaoKeGoodsDetailV2Dao.listByIds(idsList);
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listByDtitle(String dtitle) {
+
+		return daTaoKeGoodsDetailV2Dao.listByDtitle(dtitle.trim());
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listSearchByTitleWithCid(String title, Long cid, int page, int pageSize) {
+		return daTaoKeGoodsDetailV2Dao.listSearchByTitleWithCid(title, (cid == null || cid == 0 ? null : cid),
+				(page - 1) * pageSize, pageSize);
+	}
+
+	@Override
+	public Long countSearchByTitleWithCid(String title, Long cid) {
+		return daTaoKeGoodsDetailV2Dao.countSearchByTitleWithCid(title, (cid == null || cid == 0 ? null : cid));
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> getGoodsNotInList(Long cid, List<Long> listId, int count) {
+		if (cid != null && cid == 0L)
+			cid = null;
+		return daTaoKeGoodsDetailV2Dao.getGoodsNotInList(cid, listId, count);
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listPreShareHotGoods(int page, BigDecimal minCommission) {
+		Map<Long, DaTaoKeDetailV2> map = new HashMap<>();
+		List<DaTaoKeDetailV2> list = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods((page - 1) * 100, 100, "hotPush",
+				minCommission);
+		System.out.println(list);
+		for (DaTaoKeDetailV2 v2 : list) {
+			map.put(v2.getId(), v2);
+		}
+
+		List<DaTaoKeDetailV2> finalList = new ArrayList<>();
+		for (Iterator<Long> its = map.keySet().iterator(); its.hasNext();) {
+			DaTaoKeDetailV2 v2 = map.get(its.next());
+			Date time = new Date(TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"));
+			Date targetTime = new Date(TimeUtil.convertToTimeTemp(
+					TimeUtil.getGernalTime(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2L, "yyyy-MM-dd"),
+					"yyyy-MM-dd") - 1000L);
+			if (time.getTime() >= targetTime.getTime())
+				finalList.add(v2);
+		}
+
+		Comparator<DaTaoKeDetailV2> cm = new Comparator<DaTaoKeDetailV2>() {
+			@Override
+			public int compare(DaTaoKeDetailV2 o1, DaTaoKeDetailV2 o2) {
+				return o1.getActualPrice().compareTo(o2.getActualPrice());
+			}
+		};
+		Collections.sort(finalList, cm);
+		return finalList;
+	}
+
+	private boolean canAddToTLJBuyGoods(DaTaoKeDetailV2 v2) {
+		return TaoBaoUtil.canAddToTLJBuyGoods(TaoBaoUtil.convert(v2));
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listPreTLJBuyGoods(int page) {
+		if (page == 1) {
+			List<DaTaoKeDetailV2> listPreGoodsList = new ArrayList<>();
+			// 鐑攢姒�
+			DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_HOT, null);
+			if (result != null && result.getGoodsList() != null)
+				listPreGoodsList.addAll(result.getGoodsList());
+			// 澶嶈喘姒�
+			result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_REBUY, null);
+			if (result != null && result.getGoodsList() != null)
+				listPreGoodsList.addAll(result.getGoodsList());
+			// 缁煎悎鎼滅储
+			try {
+				result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
+				if (result == null)
+					throw new Exception();
+			} catch (Exception e) {// 寮傚父閲嶅涓�娆�
+				result = DaTaoKeApiUtil.search("", null, null, null, 1, 200, DaTaoKeApiUtil.SORT_DEFAULT);
+			}
+
+			if (result != null && result.getGoodsList() != null)
+				listPreGoodsList.addAll(result.getGoodsList());
+
+			List<DaTaoKeDetailV2> goodsList = new ArrayList<>();
+			for (DaTaoKeDetailV2 v2 : listPreGoodsList) {
+				if (canAddToTLJBuyGoods(v2)) {
+					Date time = new Date(TimeUtil.convertToTimeTemp(v2.getCouponEndTime(), "yyyy-MM-dd HH:mm:ss"));
+
+					Date targetTime = new Date(TimeUtil
+							.convertToTimeTemp(TimeUtil.getGernalTime(
+									System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 2L, "yyyy-MM-dd"), "yyyy-MM-dd")
+							- 1000L);
+					// 濡傛灉鏄噷鏅ㄩ�夋嫨鐨�
+					if (Calendar.getInstance().get(Calendar.HOUR_OF_DAY) < 12) {// 涓婂崍閫夋嫨鐨勮绠椾负褰撳ぉ鐨�
+						targetTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(
+								System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 1L, "yyyy-MM-dd"), "yyyy-MM-dd")
+								- 1000L);
+					}
+					if (time.getTime() >= targetTime.getTime())
+						goodsList.add(v2);
+				}
+			}
+
+			// 鍘婚噸
+			Map<String, DaTaoKeDetailV2> goodsMap = new HashMap<>();
+			for (DaTaoKeDetailV2 v2 : goodsList) {
+				goodsMap.put(v2.getGoodsId(), v2);
+			}
+			goodsList.clear();
+			for (Iterator<String> its = goodsMap.keySet().iterator(); its.hasNext();) {
+				goodsList.add(goodsMap.get(its.next()));
+			}
+			Comparator<DaTaoKeDetailV2> cm = new Comparator<DaTaoKeDetailV2>() {
+
+				@Override
+				public int compare(DaTaoKeDetailV2 o1, DaTaoKeDetailV2 o2) {
+					return o1.getActualPrice().compareTo(o2.getActualPrice());
+				}
+			};
+			Collections.sort(goodsList, cm);
+			return goodsList;
+		} else
+			return new ArrayList<>();
+	}
+
+	@Override
+	public void deleteOutOfDate(Date minTime) {
+		daTaoKeGoodsDetailV2Dao.listAndRemoveByMinUpdateTime(minTime, 0, 3000);
+	}
+
+	@Override
+	public long countByMinUpdateTime(Date minTime) {
+		return daTaoKeGoodsDetailV2Dao.countByMinUpdateTime(minTime);
+	}
+
+	@Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData'")
+	@Override
+	public List<DingDongQiangDTO> getDingDongQiangData() {
+		List<DingDongQiangDTO> list = null;
+		int count = 0;
+		while ((list == null || list.size() == 0) && count < 3) {
+			count++;
+			list = DaTaoKeUtil.getDingDongQiang();
+		}
+		if (list == null)
+			return null;
+		return list;
+	}
+
+	private void updateGoods(Long id) {
+		// TODO鏆傛椂鍏抽棴鏈嶅姟
+		DaTaoKeDetailV2 v2 = null;// DaTaoKeApiUtil.getGoodsDetail(id);
+		if (v2 != null)
+			daTaoKeGoodsDetailV2Dao.save(v2);
+	}
+
+	private List<DaTaoKeDetailV2> getDefaultDingDongQiang() {
+		// 鎸夋洿鏂版椂闂村姞
+		try {
+			DaTaoKeGoodsResult result = DaTaoKeApiUtil.getRankingList(DaTaoKeApiUtil.RANK_TYPE_TIME, null);
+			if (result != null && result.getGoodsList().size() > 0) {
+				List<DaTaoKeDetailV2> finalList = new ArrayList<>();
+				Collections.shuffle(result.getGoodsList());
+				finalList.addAll(result.getGoodsList().subList(0,
+						result.getGoodsList().size() > 8 ? 8 : result.getGoodsList().size()));
+				for (DaTaoKeDetailV2 detail : finalList) {
+					detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
+					if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
+						detail.setCouponReceiveNum(detail.getCouponTotalNum());
+				}
+				return finalList;
+			}
+		}catch(Exception e){
+
+		}
+		return null;
+	}
+
+	@Cacheable(value = "daTaoKeGoodsCache", key = "'getDingDongQiangData-'+#time")
+	@Override
+	public List<DaTaoKeDetailV2> getDingDongQiangData(String time) {
+		List<DingDongQiangDTO> list = getDingDongQiangData();
+		if (list == null || list.size() == 0) {
+			return getDefaultDingDongQiang();
+		}
+
+		Map<String, DingDongQiangDTO> map = new HashMap<>();
+		for (DingDongQiangDTO dto : list)
+			map.put(dto.getTime(), dto);
+
+		DingDongQiangDTO dto = map.get(time);
+		if (dto != null) {
+			List<Long> idList = new ArrayList<>();
+			for (DaTaoKeDetailV2 td : dto.getGoodsList())
+				idList.add(td.getId());
+			List<DaTaoKeDetailV2> finalList = listByIds(idList);
+			if (finalList.size() != idList.size()) {
+				for (Long id : idList) {
+					// updateGoods(id);
+					// TODO 涓嶈兘寮傛璋冪敤
+				}
+				finalList = listByIds(idList);
+			}
+
+			// 濡傛灉鍟嗗搧鏁板皬浜�4锛岄渶瑕佸啀鍔犲晢鍝�
+			if (finalList == null || finalList.size() <= 3) {
+				// 鎸夋洿鏂版椂闂村姞
+				List<DaTaoKeDetailV2> latestList = daTaoKeGoodsDetailV2Dao.listPreShareHotGoods(0, 50, "updateTime",
+						new BigDecimal("0.5"));
+				if (latestList != null && latestList.size() > 0) {
+					Collections.shuffle(latestList);
+					finalList.addAll(latestList.subList(0, latestList.size() > 8 ? 8 : latestList.size()));
+				}
+			}
+
+			for (DaTaoKeDetailV2 detail : finalList) {
+				detail.setCouponReceiveNum(detail.getCouponTotalNum() - (int) (200 + Math.random() * 1000));
+				if (detail.getCouponTotalNum() - detail.getCouponReceiveNum() <= 0)
+					detail.setCouponReceiveNum(detail.getCouponTotalNum());
+			}
+			return finalList;
+		} else {
+			return getDefaultDingDongQiang();
+		}
+	}
+
+	@Override
+	public List<String> getDingDongQiangTime() {
+		List<DingDongQiangDTO> list = getDingDongQiangData();
+		List<String> dateList = new ArrayList<>();
+		for (DingDongQiangDTO dto : list) {
+			dateList.add(dto.getTime());
+		}
+		return dateList;
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listByMaxPrice(Integer cid, BigDecimal maxPrice, String sortName, int page,
+			int count) {
+
+		return daTaoKeGoodsDetailV2Dao.listByMaxPrice(cid, maxPrice, sortName, (page - 1) * count, count);
+	}
+
+	@Override
+	public int countByMaxPrice(Integer cid, BigDecimal maxPrice) {
+		return (int) daTaoKeGoodsDetailV2Dao.countByMaxPrice(cid, maxPrice);
+	}
+
+	@Override
+	public List<DaTaoKeDetailV2> listBySellerId(long start, int count, Long sellerId) {
+		return daTaoKeGoodsDetailV2Dao.listBySellerId((int) start, count, sellerId);
+	}
+
+	@Override
+	public DaTaoKeDetailV2 selectByAuctionId(String auctionId) {
+		return daTaoKeGoodsDetailV2Dao.selectByAuctionId(auctionId);
+	}
+
+	@Cacheable(value = "daTaoKeGoodsCache", key = "'selectByAuctionId-'+#auctionId")
+	@Override
+	public DaTaoKeDetailV2 selectByAuctionIdCache(String auctionId) {
+		return selectByAuctionId(auctionId);
+	}
+
+	@Override
+	public DaTaoKeFilterResult filterTaoBaoGoods(TaoBaoGoodsBrief goods) {
+		List<String> goodsIdList = new ArrayList<>();
+		goodsIdList.add(goods.getAuctionId());
+
+		List<DaTaoKeDetailV2> daTaoKeList = listByGoodsIds(goodsIdList);
+		if (daTaoKeList == null || daTaoKeList.size() == 0)
+			return new DaTaoKeFilterResult(goods, DaTaoKeFilterResult.FILTER_TYPE_NONE);
+		// 閲嶆柊璁剧疆鏍囬涓庡埜浠锋牸
+		return DaTaoKeUtil.filterTaoBaoGoods(goods, daTaoKeList.get(0), true);
+	}
+
+}

--
Gitblit v1.8.0