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/goods/JDCommonTemplateContentServiceImpl.java | 268 ++++++++++++++++++++++++++-------------------------- 1 files changed, 134 insertions(+), 134 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/JDCommonTemplateContentServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/JDCommonTemplateContentServiceImpl.java index c971325..9d5ef39 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/JDCommonTemplateContentServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/JDCommonTemplateContentServiceImpl.java @@ -1,134 +1,134 @@ -package com.yeshi.fanli.service.impl.goods; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; - -import com.yeshi.fanli.dto.common.JDCommonContentTypeEnum; -import com.yeshi.fanli.dto.jd.JDSearchResult; -import com.yeshi.fanli.entity.jd.JDGoods; -import com.yeshi.fanli.service.inter.goods.JDCommonTemplateContentService; -import com.yeshi.common.entity.PageEntity; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.jd.JDApiUtil; - -@Service -public class JDCommonTemplateContentServiceImpl implements JDCommonTemplateContentService { - - private Map<String, Long> countMap = new HashMap<String, Long>(); - - @Cacheable(value = "jdCommonContentCache", key = "#type+'-'+#cid+'-'+#page+'-'+#pageSize") - @Override - public JDSearchResult getContentList(JDCommonContentTypeEnum type, String cid, int page, int pageSize) { - if (type == JDCommonContentTypeEnum._9k9) { - return get9K9Content(cid, page, pageSize); - } else if (type == JDCommonContentTypeEnum.jdPeiSong) { - return getJDPeiSongContent(cid, page, pageSize); - } else if (type == JDCommonContentTypeEnum.jiaDian) { - return getJiaDianContent(cid, page, pageSize); - } else if (type == JDCommonContentTypeEnum.baiHuo) { - return getBaiHuoContent(cid, page, pageSize); - } else if (type == JDCommonContentTypeEnum.juJia) { - return getJuJiaContent(cid, page, pageSize); - } - return null; - } - - private JDSearchResult get9K9Content(String cid, int page, int pageSize) { - int[] arrayId = { 10, 17 }; - JDSearchResult result = getJingFenGoods(page, pageSize, "9k9-", arrayId); - - return filterGoods(result); - } - - private JDSearchResult filterGoods(JDSearchResult result) { - List<Long> skuIds = new ArrayList<>(); - if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0) { - for (JDGoods goods : result.getGoodsList()) { - skuIds.add(goods.getSkuId()); - } - List<JDGoods> goodsList = JDApiUtil.listGoodsDetail(skuIds); - result.setGoodsList(goodsList); - } - return result; - } - - private JDSearchResult getJDPeiSongContent(String cid, int page, int pageSize) { - int[] arrayId = { 15, 18 }; - JDSearchResult result = getJingFenGoods(page, pageSize, "peisong-", arrayId); - return filterGoods(result); - } - - private JDSearchResult getJiaDianContent(String cid, int page, int pageSize) { - int[] arrayId = { 5, 2 }; - JDSearchResult result = getJingFenGoods(page, pageSize, "jiadian-", arrayId); - return filterGoods(result); - } - - private JDSearchResult getBaiHuoContent(String cid, int page, int pageSize) { - int[] arrayId = { 6, 3 }; - JDSearchResult result = getJingFenGoods(page, pageSize, "baihuo-", arrayId); - return filterGoods(result); - } - - private JDSearchResult getJuJiaContent(String cid, int page, int pageSize) { - int[] arrayId = { 7, 4 }; - JDSearchResult result = getJingFenGoods(page, pageSize, "jujia-", arrayId); - return filterGoods(result); - } - - /** - * 9蹇�9鍖呴偖 - * - * @param cid - * @param page - * @param pageSize - * @return - */ - private JDSearchResult getJingFenGoods(int page, int pageSize, String mapKey, int[] arrayId) { - int pageTemp = 0; - long addCount = 0; - Integer categoryId = null; - long totalCount = (long) (page * Constant.PAGE_SIZE); - for (int i = 0; i < arrayId.length; i++) { - Long count = countMap.get(mapKey + arrayId[i]); - if (count != null) { - addCount += count; - } - - if (count != null && totalCount > addCount) { - pageTemp = (int) (addCount / Constant.PAGE_SIZE); - continue; // 褰撳墠鍒嗙被鍟嗗搧涓嶈冻 - } else { - page = page - pageTemp; - categoryId = arrayId[i]; - 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(mapKey + categoryId, mcount); - return result; - } - -} +package com.yeshi.fanli.service.impl.goods; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; + +import com.yeshi.fanli.dto.common.JDCommonContentTypeEnum; +import com.yeshi.fanli.dto.jd.JDSearchResult; +import com.yeshi.fanli.entity.jd.JDGoods; +import com.yeshi.fanli.service.inter.goods.JDCommonTemplateContentService; +import com.yeshi.common.entity.PageEntity; +import com.yeshi.fanli.util.Constant; +import com.yeshi.fanli.util.jd.JDApiUtil; + +@Service +public class JDCommonTemplateContentServiceImpl implements JDCommonTemplateContentService { + + private Map<String, Long> countMap = new HashMap<String, Long>(); + + @Cacheable(value = "jdCommonContentCache", key = "#type+'-'+#cid+'-'+#page+'-'+#pageSize") + @Override + public JDSearchResult getContentList(JDCommonContentTypeEnum type, String cid, int page, int pageSize) { + if (type == JDCommonContentTypeEnum._9k9) { + return get9K9Content(cid, page, pageSize); + } else if (type == JDCommonContentTypeEnum.jdPeiSong) { + return getJDPeiSongContent(cid, page, pageSize); + } else if (type == JDCommonContentTypeEnum.jiaDian) { + return getJiaDianContent(cid, page, pageSize); + } else if (type == JDCommonContentTypeEnum.baiHuo) { + return getBaiHuoContent(cid, page, pageSize); + } else if (type == JDCommonContentTypeEnum.juJia) { + return getJuJiaContent(cid, page, pageSize); + } + return null; + } + + private JDSearchResult get9K9Content(String cid, int page, int pageSize) { + int[] arrayId = { 10, 17 }; + JDSearchResult result = getJingFenGoods(page, pageSize, "9k9-", arrayId); + + return filterGoods(result); + } + + private JDSearchResult filterGoods(JDSearchResult result) { + List<String> skuIds = new ArrayList<>(); + if (result != null && result.getGoodsList() != null && result.getGoodsList().size() > 0) { + for (JDGoods goods : result.getGoodsList()) { + skuIds.add(goods.getItemId()); + } + List<JDGoods> goodsList = JDApiUtil.listGoodsDetail(skuIds); + result.setGoodsList(goodsList); + } + return result; + } + + private JDSearchResult getJDPeiSongContent(String cid, int page, int pageSize) { + int[] arrayId = { 15, 18 }; + JDSearchResult result = getJingFenGoods(page, pageSize, "peisong-", arrayId); + return filterGoods(result); + } + + private JDSearchResult getJiaDianContent(String cid, int page, int pageSize) { + int[] arrayId = { 24}; + JDSearchResult result = getJingFenGoods(page, pageSize, "jiadian-", arrayId); + return filterGoods(result); + } + + private JDSearchResult getBaiHuoContent(String cid, int page, int pageSize) { + int[] arrayId = { 25 }; + JDSearchResult result = getJingFenGoods(page, pageSize, "baihuo-", arrayId); + return filterGoods(result); + } + + private JDSearchResult getJuJiaContent(String cid, int page, int pageSize) { + int[] arrayId = { 27 }; + JDSearchResult result = getJingFenGoods(page, pageSize, "jujia-", arrayId); + return filterGoods(result); + } + + /** + * 9蹇�9鍖呴偖 + * + * @param cid + * @param page + * @param pageSize + * @return + */ + private JDSearchResult getJingFenGoods(int page, int pageSize, String mapKey, int[] arrayId) { + int pageTemp = 0; + long addCount = 0; + Integer categoryId = null; + long totalCount = (long) (page * Constant.PAGE_SIZE); + for (int i = 0; i < arrayId.length; i++) { + Long count = countMap.get(mapKey + arrayId[i]); + if (count != null) { + addCount += count; + } + + if (count != null && totalCount > addCount) { + pageTemp = (int) (addCount / Constant.PAGE_SIZE); + continue; // 褰撳墠鍒嗙被鍟嗗搧涓嶈冻 + } else { + page = page - pageTemp; + categoryId = arrayId[i]; + 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(mapKey + categoryId, mcount); + return result; + } + +} -- Gitblit v1.8.0