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/jd/JDGoodsServiceImpl.java |  474 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 238 insertions(+), 236 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java
index 5182896..41d6d0a 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/jd/JDGoodsServiceImpl.java
@@ -1,236 +1,238 @@
-package com.yeshi.fanli.service.impl.jd;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Resource;
-
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.yeshi.fanli.dto.jd.JDFilter;
-import com.yeshi.fanli.dto.jd.JDSearchFilter;
-import com.yeshi.fanli.dto.jd.JDSearchResult;
-import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
-import com.yeshi.fanli.entity.jd.JDGoods;
-import com.yeshi.fanli.exception.jd.JDGoodsException;
-import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
-import com.yeshi.fanli.service.inter.jd.JDGoodsService;
-import com.yeshi.fanli.tag.PageEntity;
-import com.yeshi.fanli.util.Constant;
-import com.yeshi.fanli.util.StringUtil;
-import com.yeshi.fanli.util.jd.JDApiUtil;
-import com.yeshi.fanli.util.jd.JDUtil;
-
-@Service
-public class JDGoodsServiceImpl implements JDGoodsService {
-
-	@Resource
-	private ConfigService configService;
-
-	@Resource
-	private HongBaoManageService hongBaoManageService;
-
-	private Map<String, Long> countMap = new HashMap<String, Long>();
-	private static final Map<Long, String> cidMap = new HashMap<Long, String>();
-
-	static {
-		cidMap.put(1L, "2,16,1,3");// 绮鹃��
-		cidMap.put(2L, "737");// 鐢靛櫒锛� 瀹剁敤鐢靛櫒
-		cidMap.put(3L, "652,670");// 鏁扮爜锛� 鏁扮爜/鐢佃剳銆佸姙鍏�
-		cidMap.put(4L, "9987");// 鎵嬫満锛氭墜鏈洪�氳
-		cidMap.put(5L, "12218");// 鐢熼矞
-		cidMap.put(6L, "1315");// 鏈嶉グ锛� 鏈嶉グ鍐呰。
-		cidMap.put(7L, "1319,6233");// 姣嶅┐锛� 姣嶅┐/鐜╁叿涔愬櫒
-		cidMap.put(8L, "1713");// 鍥句功
-		cidMap.put(9L, "6196");// 鍘ㄥ叿
-		cidMap.put(10L, "1320");// 椋熷搧锛� 椋熷搧楗枡
-		cidMap.put(11L, "1316,16750");// 缇庡锛� 缇庡鎶よ偆/涓汉鎶ょ悊
-		cidMap.put(12L, "15901,1620,1672,12259,9192");// 鐧捐揣锛氬搴竻娲併�佺焊鍝�/灞呭鏃ョ敤/绀煎搧/閰掔被/鍖昏嵂淇濆仴
-		cidMap.put(13L, "11729");// 闉嬮澊
-		cidMap.put(14L, "1318");// 杩愬姩锛氳繍鍔ㄦ埛澶�
-		cidMap.put(15L, "17329");// 绠卞寘锛� 绠卞寘鐨叿
-		cidMap.put(16L, "6994");// 瀹犵墿锛� 瀹犵墿鐢熸椿
-		cidMap.put(17L, "9855,9847,15248");// 瀹跺眳锛� 瀹惰寤烘潗/瀹跺叿/瀹剁汉
-		cidMap.put(18L, "6728");// 姹借溅锛氭苯杞︾敤鍝�
-	}
-
-	@Override
-	public List<GoodsClass> getSpecialClass() {
-		List<GoodsClass> list = new ArrayList<GoodsClass>();
-		list.add(new GoodsClass(1L, "绮鹃��"));
-		list.add(new GoodsClass(2L, "鐢靛櫒"));
-		list.add(new GoodsClass(3L, "鏁扮爜"));
-		list.add(new GoodsClass(4L, "鎵嬫満"));
-		list.add(new GoodsClass(5L, "鐢熼矞"));
-		list.add(new GoodsClass(6L, "鏈嶉グ"));
-		list.add(new GoodsClass(7L, "姣嶅┐"));
-		list.add(new GoodsClass(8L, "鍥句功"));
-		list.add(new GoodsClass(9L, "鍘ㄥ叿"));
-		list.add(new GoodsClass(10L, "椋熷搧"));
-		list.add(new GoodsClass(11L, "缇庡"));
-		list.add(new GoodsClass(12L, "鐧捐揣"));
-		list.add(new GoodsClass(13L, "闉嬮澊"));
-		list.add(new GoodsClass(14L, "杩愬姩"));
-		list.add(new GoodsClass(15L, "绠卞寘"));
-		list.add(new GoodsClass(16L, "瀹犵墿"));
-		list.add(new GoodsClass(17L, "瀹跺眳"));
-		list.add(new GoodsClass(18L, "姹借溅"));
-		return list;
-	}
-
-	@Cacheable(value = "jdSpecialCache", key = "'specialSearch-'+#page+'-'+#cid")
-	@Override
-	@Transactional
-	public List<JDGoods> specialSearch(Integer page, Long cid) throws JDGoodsException {
-		if (cid == null) {
-			throw new JDGoodsException(1, "鍒嗙被id涓虹┖");
-		}
-
-		String jdcid = cidMap.get(cid);
-		if (StringUtil.isNullOrEmpty(jdcid)) {
-			throw new JDGoodsException(1, "鍒嗙被id涓嶅瓨鍦�");
-		}
-
-		// 绮鹃��
-		if (cid == 1) {
-			Integer categoryId = null;
-			int pageTemp = 0;
-			long addCount = 0;
-			long totalCount = (long) (page * Constant.PAGE_SIZE);
-			String[] arrayId = jdcid.split(",");
-			for (int i = 0; i < arrayId.length; i++) {
-				String id = arrayId[i];
-				Long count = countMap.get(cid + "-" + id);
-				if (count != null) {
-					addCount += count;
-				}
-
-				if (count != null && totalCount > addCount) {
-					pageTemp = (int) (addCount / Constant.PAGE_SIZE);
-					continue; // 褰撳墠鍒嗙被鍟嗗搧涓嶈冻
-				} else {
-					page = page - pageTemp;
-					categoryId = Integer.parseInt(id);
-					break;
-				}
-			}
-
-			if (categoryId == null) {
-				return null;
-			}
-
-			JDSearchResult result = JDApiUtil.getJingFenGoods(page, categoryId);
-
-			long count = 0;
-			if (result != null) {
-				PageEntity pageEntity = result.getPageEntity();
-				if (pageEntity != null) {
-					count = pageEntity.getTotalCount();
-				}
-			}
-
-			long mcount = (count / Constant.PAGE_SIZE) * Constant.PAGE_SIZE;
-			if (mcount == 0) {
-				mcount = 20;
-			}
-			countMap.put(cid + "-" + categoryId, mcount);
-
-			if (result == null) {
-				return null;
-			} else {
-				return filterJDGoods(result.getGoodsList());
-			}
-		}
-
-		if (!jdcid.contains(",")) {
-			return search(page, Constant.PAGE_SIZE, jdcid);
-		}
-
-		// 澶氫釜鍒嗙被id澶勭悊
-		List<JDGoods> list = new ArrayList<JDGoods>();
-		String[] arrayId = jdcid.split(",");
-		for (int i = 0; i < arrayId.length; i++) {
-			if (i >= 3) {
-				break;
-			}
-			List<JDGoods> listGoods = search(page, 10, arrayId[i]);
-			if (listGoods != null && listGoods.size() > 0) {
-				list.addAll(listGoods);
-			}
-		}
-		return filterJDGoods(list);
-	}
-
-	/**
-	 * 杩囨护鍟嗗搧
-	 * 
-	 * @param goodsList
-	 * @return
-	 */
-	private List<JDGoods> filterJDGoods(List<JDGoods> goodsList) {
-		List<Long> skuIds = new ArrayList<>();
-		for (JDGoods goods : goodsList) {
-			skuIds.add(goods.getSkuId());
-		}
-		List<JDGoods> newGoodsList = JDApiUtil.listGoodsDetail(skuIds);
-		if (newGoodsList != null && newGoodsList.size() > 0)
-			return newGoodsList;
-		return goodsList;
-	}
-
-	private List<JDGoods> search(int page, int pageSize, String jdcid) {
-		JDSearchResult result = null;
-		String way = configService.get("jd_api_search_key");
-		if ("1".equals(way)) { // API鎼滅储
-			JDFilter filterAPI = new JDFilter();
-			filterAPI.setPageIndex(page);
-			filterAPI.setPageSize(pageSize);
-			filterAPI.setCid1(Long.parseLong(jdcid));
-			result = JDApiUtil.queryByKey(filterAPI);
-		} else { // 缃戦〉鐖彇
-			JDSearchFilter jdfilter = new JDSearchFilter();
-			jdfilter.setPageNo(page);
-			jdfilter.setPageSize(pageSize);
-			jdfilter.setCategoryId(Integer.parseInt(jdcid));
-			result = JDUtil.searchByKey(jdfilter);
-		}
-
-		if (result == null) {
-			return null;
-		} else {
-			return result.getGoodsList();
-		}
-	}
-
-	@Cacheable(value = "jdCache", key = "'getIndexJDGoods-'+#page")
-	@Override
-	public JDSearchResult getIndexJDGoods(int page) {
-		JDSearchResult result = null;
-		String way = configService.get("jd_api_search_key");
-		// TODO 闇�瑕佽皟鏁磋鍒�
-		way = "0";
-		if ("1".equals(way)) {
-			JDFilter filterAPI = new JDFilter();
-			filterAPI.setPageIndex(page);
-			filterAPI.setPageSize(20);
-			result = JDApiUtil.queryByKey(filterAPI);
-		} else {
-			// 缃戦〉鐖彇
-			JDSearchFilter jdfilter = new JDSearchFilter();
-			jdfilter.setPageNo(page);
-			jdfilter.setPageSize(Constant.PAGE_SIZE);
-			result = JDUtil.searchByKey(jdfilter);
-		}
-		if (result != null && result.getGoodsList() != null)
-			Collections.shuffle(result.getGoodsList());
-
-		return result;
-	}
-
-}
+package com.yeshi.fanli.service.impl.jd;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import com.yeshi.fanli.entity.SystemEnum;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.yeshi.fanli.dto.jd.JDFilter;
+import com.yeshi.fanli.dto.jd.JDSearchFilter;
+import com.yeshi.fanli.dto.jd.JDSearchResult;
+import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
+import com.yeshi.fanli.entity.jd.JDGoods;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
+import com.yeshi.fanli.exception.jd.JDGoodsException;
+import com.yeshi.fanli.service.inter.config.ConfigService;
+import com.yeshi.fanli.service.inter.jd.JDGoodsService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
+import com.yeshi.common.entity.PageEntity;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.StringUtil;
+import com.yeshi.fanli.util.jd.JDApiUtil;
+import com.yeshi.fanli.util.jd.JDUtil;
+
+@Service
+public class JDGoodsServiceImpl implements JDGoodsService {
+
+	@Resource
+	private ConfigService configService;
+
+	@Resource
+	private HongBaoManageService hongBaoManageService;
+
+	private Map<String, Long> countMap = new HashMap<String, Long>();
+	private static final Map<Long, String> cidMap = new HashMap<Long, String>();
+
+	static {
+		cidMap.put(1L, "2,16,1,3");// 绮鹃��
+		cidMap.put(2L, "737");// 鐢靛櫒锛� 瀹剁敤鐢靛櫒
+		cidMap.put(3L, "652,670");// 鏁扮爜锛� 鏁扮爜/鐢佃剳銆佸姙鍏�
+		cidMap.put(4L, "9987");// 鎵嬫満锛氭墜鏈洪�氳
+		cidMap.put(5L, "12218");// 鐢熼矞
+		cidMap.put(6L, "1315");// 鏈嶉グ锛� 鏈嶉グ鍐呰。
+		cidMap.put(7L, "1319,6233");// 姣嶅┐锛� 姣嶅┐/鐜╁叿涔愬櫒
+		cidMap.put(8L, "1713");// 鍥句功
+		cidMap.put(9L, "6196");// 鍘ㄥ叿
+		cidMap.put(10L, "1320");// 椋熷搧锛� 椋熷搧楗枡
+		cidMap.put(11L, "1316,16750");// 缇庡锛� 缇庡鎶よ偆/涓汉鎶ょ悊
+		cidMap.put(12L, "15901,1620,1672,12259,9192");// 鐧捐揣锛氬搴竻娲併�佺焊鍝�/灞呭鏃ョ敤/绀煎搧/閰掔被/鍖昏嵂淇濆仴
+		cidMap.put(13L, "11729");// 闉嬮澊
+		cidMap.put(14L, "1318");// 杩愬姩锛氳繍鍔ㄦ埛澶�
+		cidMap.put(15L, "17329");// 绠卞寘锛� 绠卞寘鐨叿
+		cidMap.put(16L, "6994");// 瀹犵墿锛� 瀹犵墿鐢熸椿
+		cidMap.put(17L, "9855,9847,15248");// 瀹跺眳锛� 瀹惰寤烘潗/瀹跺叿/瀹剁汉
+		cidMap.put(18L, "6728");// 姹借溅锛氭苯杞︾敤鍝�
+	}
+
+	@Override
+	public List<GoodsClass> getSpecialClass() {
+		List<GoodsClass> list = new ArrayList<GoodsClass>();
+		list.add(new GoodsClass(1L, "绮鹃��"));
+		list.add(new GoodsClass(2L, "鐢靛櫒"));
+		list.add(new GoodsClass(3L, "鏁扮爜"));
+		list.add(new GoodsClass(4L, "鎵嬫満"));
+		list.add(new GoodsClass(5L, "鐢熼矞"));
+		list.add(new GoodsClass(6L, "鏈嶉グ"));
+		list.add(new GoodsClass(7L, "姣嶅┐"));
+		list.add(new GoodsClass(8L, "鍥句功"));
+		list.add(new GoodsClass(9L, "鍘ㄥ叿"));
+		list.add(new GoodsClass(10L, "椋熷搧"));
+		list.add(new GoodsClass(11L, "缇庡"));
+		list.add(new GoodsClass(12L, "鐧捐揣"));
+		list.add(new GoodsClass(13L, "闉嬮澊"));
+		list.add(new GoodsClass(14L, "杩愬姩"));
+		list.add(new GoodsClass(15L, "绠卞寘"));
+		list.add(new GoodsClass(16L, "瀹犵墿"));
+		list.add(new GoodsClass(17L, "瀹跺眳"));
+		list.add(new GoodsClass(18L, "姹借溅"));
+		return list;
+	}
+
+	@Cacheable(value = "jdSpecialCache", key = "'specialSearch-'+#page+'-'+#cid")
+	@Override
+	@Transactional(rollbackFor=Exception.class)
+	public List<JDGoods> specialSearch(Integer page, Long cid,SystemEnum system) throws JDGoodsException {
+		if (cid == null) {
+			throw new JDGoodsException(1, "鍒嗙被id涓虹┖");
+		}
+
+		String jdcid = cidMap.get(cid);
+		if (StringUtil.isNullOrEmpty(jdcid)) {
+			throw new JDGoodsException(1, "鍒嗙被id涓嶅瓨鍦�");
+		}
+
+		// 绮鹃��
+		if (cid == 1) {
+			Integer categoryId = null;
+			int pageTemp = 0;
+			long addCount = 0;
+			long totalCount = (long) (page * Constant.PAGE_SIZE);
+			String[] arrayId = jdcid.split(",");
+			for (int i = 0; i < arrayId.length; i++) {
+				String id = arrayId[i];
+				Long count = countMap.get(cid + "-" + id);
+				if (count != null) {
+					addCount += count;
+				}
+
+				if (count != null && totalCount > addCount) {
+					pageTemp = (int) (addCount / Constant.PAGE_SIZE);
+					continue; // 褰撳墠鍒嗙被鍟嗗搧涓嶈冻
+				} else {
+					page = page - pageTemp;
+					categoryId = Integer.parseInt(id);
+					break;
+				}
+			}
+
+			if (categoryId == null) {
+				return null;
+			}
+
+			JDSearchResult result = JDApiUtil.getJingFenGoods(page, categoryId);
+
+			long count = 0;
+			if (result != null) {
+				PageEntity pageEntity = result.getPageEntity();
+				if (pageEntity != null) {
+					count = pageEntity.getTotalCount();
+				}
+			}
+
+			long mcount = (count / Constant.PAGE_SIZE) * Constant.PAGE_SIZE;
+			if (mcount == 0) {
+				mcount = 20;
+			}
+			countMap.put(cid + "-" + categoryId, mcount);
+
+			if (result == null) {
+				return null;
+			} else {
+				return filterJDGoods(result.getGoodsList());
+			}
+		}
+
+		if (!jdcid.contains(",")) {
+			return search(page, Constant.PAGE_SIZE, jdcid,system);
+		}
+
+		// 澶氫釜鍒嗙被id澶勭悊
+		List<JDGoods> list = new ArrayList<JDGoods>();
+		String[] arrayId = jdcid.split(",");
+		for (int i = 0; i < arrayId.length; i++) {
+			if (i >= 3) {
+				break;
+			}
+			List<JDGoods> listGoods = search(page, 10, arrayId[i],system);
+			if (listGoods != null && listGoods.size() > 0) {
+				list.addAll(listGoods);
+			}
+		}
+		return filterJDGoods(list);
+	}
+
+	/**
+	 * 杩囨护鍟嗗搧
+	 * 
+	 * @param goodsList
+	 * @return
+	 */
+	private List<JDGoods> filterJDGoods(List<JDGoods> goodsList) {
+		List<String> skuIds = new ArrayList<>();
+		for (JDGoods goods : goodsList) {
+			skuIds.add(goods.getItemId());
+		}
+		List<JDGoods> newGoodsList = JDApiUtil.listGoodsDetail(skuIds);
+		if (newGoodsList != null && newGoodsList.size() > 0)
+			return newGoodsList;
+		return goodsList;
+	}
+
+	private List<JDGoods> search(int page, int pageSize, String jdcid, SystemEnum system) {
+		JDSearchResult result = null;
+		String way = configService.getValue(ConfigKeyEnum.jdApiSearchKey.getKey(),system);
+		if ("1".equals(way)) { // API鎼滅储
+			JDFilter filterAPI = new JDFilter();
+			filterAPI.setPageIndex(page);
+			filterAPI.setPageSize(pageSize);
+			filterAPI.setCid1(Long.parseLong(jdcid));
+			result = JDApiUtil.queryByKey(filterAPI);
+		} else { // 缃戦〉鐖彇
+			JDSearchFilter jdfilter = new JDSearchFilter();
+			jdfilter.setPageNo(page);
+			jdfilter.setPageSize(pageSize);
+			jdfilter.setCategoryId(Integer.parseInt(jdcid));
+			result = JDUtil.searchByKey(jdfilter);
+		}
+
+		if (result == null) {
+			return null;
+		} else {
+			return result.getGoodsList();
+		}
+	}
+
+	@Cacheable(value = "jdCache", key = "'getIndexJDGoods-'+#page")
+	@Override
+	public JDSearchResult getIndexJDGoods(int page,SystemEnum system) {
+		JDSearchResult result = null;
+		String way = configService.getValue(ConfigKeyEnum.jdApiSearchKey.getKey(),system);
+		// TODO 闇�瑕佽皟鏁磋鍒�
+		way = "0";
+		if ("1".equals(way)) {
+			JDFilter filterAPI = new JDFilter();
+			filterAPI.setPageIndex(page);
+			filterAPI.setPageSize(20);
+			result = JDApiUtil.queryByKey(filterAPI);
+		} else {
+			// 缃戦〉鐖彇
+			JDSearchFilter jdfilter = new JDSearchFilter();
+			jdfilter.setPageNo(page);
+			jdfilter.setPageSize(Constant.PAGE_SIZE);
+			result =JDApiUtil.getJingFenGoods(page,125); //JDUtil.searchByKey(jdfilter);
+		}
+		if (result != null && result.getGoodsList() != null)
+			Collections.shuffle(result.getGoodsList());
+
+		return result;
+	}
+
+}

--
Gitblit v1.8.0