| | |
| | | package com.yeshi.fanli.service.impl.special;
|
| | |
|
| | | import java.io.UnsupportedEncodingException;
|
| | | import java.math.BigDecimal;
|
| | | import java.net.URLEncoder;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
|
| | | import com.yeshi.fanli.entity.bus.recommend.RecommendBanner;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.special.S11Service;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.RedisManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | @Service
|
| | | public class S11ServiceImpl implements S11Service {
|
| | |
|
| | | /**
|
| | | * 双11分类
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | public enum S11ClassEnum {
|
| | | nvzhuang("16", "女装",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_nvzhuang.png"), jiajujiazhuang(
|
| | | "50020808,50020485,50020485,50007216,50020611,50008164,124354002,50074001,26,122852001", "家居家装",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_jiayujiazhuang.png"), shumajiadian(
|
| | | "14,1101,50019780,124242008,50007218,11,50018264,50012164,50011972,1512,50022703,50012100,50012082",
|
| | | "数码家电",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_shumajiadian.png"), muying(
|
| | | "35,50014812,50022517,50008165,122650005,25", "母婴",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_muying.png"), shipin(
|
| | | "50008075,50020275,50002766,50016422,50026316,50050359,50026800,50008141,123690003,124458005",
|
| | | "食品",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_shipin.png"), xiebaopeishi(
|
| | | "50011740,50006843,50012029,50010404,50013864,50011397,28,50468001,50023722",
|
| | | "鞋包配饰",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_xiebaopeishi.png"), meizhuanggehu(
|
| | | "50010788,50023282,1801", "美妆个护",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_meizhuanggehu.png"), nanzhuang(
|
| | | "30", "男装",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_nanzhuang.png"), neiyi(
|
| | | "1625,2813", "内衣",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_neiyi.png"), yundonghuwai(
|
| | | "50010728,50013886,50011699,50510002,122684003",
|
| | | "运动户外",
|
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_yundonghuwai.png");
|
| | | private final String taoBaoClassIds;
|
| | | private final String name;
|
| | | private final String icon;
|
| | |
|
| | | private S11ClassEnum(String taoBaoClassIds, String name, String icon) {
|
| | | this.taoBaoClassIds = taoBaoClassIds;
|
| | | this.name = name;
|
| | | this.icon = icon;
|
| | | }
|
| | |
|
| | | public String getTaoBaoClassIds() {
|
| | | return taoBaoClassIds;
|
| | | }
|
| | |
|
| | | public String getName() {
|
| | | return name;
|
| | | }
|
| | |
|
| | | public String getIcon() {
|
| | | return icon;
|
| | | }
|
| | | }
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Cacheable(value = "s11Cache", key = "'getPreSaleGoodsCache'+#page")
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> getPreSaleGoodsCache(int page) {
|
| | | String key = "s11_presale_goods-" + page;
|
| | | try {
|
| | | String resultStr = redisManager.getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(resultStr)) {
|
| | | return new Gson().fromJson(resultStr, new TypeToken<List<TaoBaoGoodsBrief>>() {
|
| | | }.getType());
|
| | | }
|
| | | } catch (Exception e) {
|
| | |
|
| | | }
|
| | |
|
| | | TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(8452, page, Constant.PAGE_SIZE);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
|
| | | try {
|
| | | redisManager.cacheCommonString("s11_presale_goods-" + page,
|
| | | new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 60);// 缓存1小时
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return result.getTaoBaoGoodsBriefs();
|
| | | } else
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<GoodsClass> getGoodsClassCache() {
|
| | | List<GoodsClass> list = new ArrayList<>();
|
| | | S11ClassEnum[] values = S11ClassEnum.values();
|
| | | for (S11ClassEnum se : values) {
|
| | | GoodsClass gc = new GoodsClass();
|
| | | gc.setKey(se.name());
|
| | | gc.setPicture(se.getIcon());
|
| | | gc.setName(se.getName());
|
| | | try {
|
| | | gc.setUrl("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_11_class.js?key=" + se.name()
|
| | | + "&title=" + URLEncoder.encode(se.getName(), "UTF-8"));
|
| | | } catch (UnsupportedEncodingException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | list.add(gc);
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<RecommendBanner> getBanner() {
|
| | | RecommendBanner recommendBanner = new RecommendBanner();
|
| | | recommendBanner.setPicture("http://ec-1255749512.file.myqcloud.com/resource/s11/class_banner.jpg");
|
| | | List<RecommendBanner> list = new ArrayList<>();
|
| | | list.add(recommendBanner);
|
| | | return list;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "s11Cache", key = "'getPreSaleGoodsByType-'+#type+'-'+#page")
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> getPreSaleGoodsByType(String type, int page) {
|
| | | String classIds = S11ClassEnum.valueOf(type).getTaoBaoClassIds();
|
| | | SearchFilter sf = new SearchFilter();
|
| | | sf.setCateIds(classIds);
|
| | | // sf.setMaterialId("8440");
|
| | | sf.setKey("双11");
|
| | | sf.setEndPrice(new BigDecimal("220"));
|
| | | sf.setQuan(1);
|
| | | sf.setPage(page);
|
| | | sf.setPageSize(Constant.PAGE_SIZE);
|
| | |
|
| | | String key = "s11_presale_goods-type-" + type + "-" + page;
|
| | | try {
|
| | | String resultStr = redisManager.getCommonString(key);
|
| | | if (!StringUtil.isNullOrEmpty(resultStr)) {
|
| | | return new Gson().fromJson(resultStr, new TypeToken<List<TaoBaoGoodsBrief>>() {
|
| | | }.getType());
|
| | | }
|
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiao(sf);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
|
| | | try {
|
| | | redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 60);// 缓存1小时
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return result.getTaoBaoGoodsBriefs();
|
| | | } else
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.special; |
| | | |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.math.BigDecimal; |
| | | import java.net.URLEncoder; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass; |
| | | import com.yeshi.fanli.entity.bus.recommend.RecommendBanner; |
| | | import com.yeshi.fanli.entity.taobao.SearchFilter; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.special.S11Service; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import com.yeshi.fanli.util.RedisKeyEnum; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | |
| | | @Service |
| | | public class S11ServiceImpl implements S11Service { |
| | | |
| | | /** |
| | | * 双11分类 |
| | | * |
| | | * @author Administrator |
| | | * |
| | | */ |
| | | public enum S11ClassEnum { |
| | | nvzhuang("16", "女装", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_nvzhuang.png"), jiajujiazhuang( |
| | | "50020808,50020485,50020485,50007216,50020611,50008164,124354002,50074001,26,122852001", "家居家装", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_jiayujiazhuang.png"), shumajiadian( |
| | | "14,1101,50019780,124242008,50007218,11,50018264,50012164,50011972,1512,50022703,50012100,50012082", |
| | | "数码家电", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_shumajiadian.png"), muying( |
| | | "35,50014812,50022517,50008165,122650005,25", "母婴", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_muying.png"), shipin( |
| | | "50008075,50020275,50002766,50016422,50026316,50050359,50026800,50008141,123690003,124458005", |
| | | "食品", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_shipin.png"), xiebaopeishi( |
| | | "50011740,50006843,50012029,50010404,50013864,50011397,28,50468001,50023722", |
| | | "鞋包配饰", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_xiebaopeishi.png"), meizhuanggehu( |
| | | "50010788,50023282,1801", "美妆个护", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_meizhuanggehu.png"), nanzhuang( |
| | | "30", "男装", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_nanzhuang.png"), neiyi( |
| | | "1625,2813", "内衣", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_neiyi.png"), yundonghuwai( |
| | | "50010728,50013886,50011699,50510002,122684003", |
| | | "运动户外", |
| | | "http://ec-1255749512.file.myqcloud.com/resource/s11/class/icon_yundonghuwai.png"); |
| | | private final String taoBaoClassIds; |
| | | private final String name; |
| | | private final String icon; |
| | | |
| | | private S11ClassEnum(String taoBaoClassIds, String name, String icon) { |
| | | this.taoBaoClassIds = taoBaoClassIds; |
| | | this.name = name; |
| | | this.icon = icon; |
| | | } |
| | | |
| | | public String getTaoBaoClassIds() { |
| | | return taoBaoClassIds; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public String getIcon() { |
| | | return icon; |
| | | } |
| | | } |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Cacheable(value = "s11Cache", key = "'getPreSaleGoodsCache'+#page") |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> getPreSaleGoodsCache(int page) { |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.S11PresaleGoods, page +""); |
| | | try { |
| | | String resultStr = redisManager.getCommonString(key); |
| | | if (!StringUtil.isNullOrEmpty(resultStr)) { |
| | | return new Gson().fromJson(resultStr, new TypeToken<List<TaoBaoGoodsBrief>>() { |
| | | }.getType()); |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | |
| | | TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(8452, page, Constant.PAGE_SIZE); |
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) { |
| | | try { |
| | | redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 60);// 缓存1小时 |
| | | } catch (Exception e) { |
| | | } |
| | | return result.getTaoBaoGoodsBriefs(); |
| | | } else |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public List<GoodsClass> getGoodsClassCache() { |
| | | List<GoodsClass> list = new ArrayList<>(); |
| | | S11ClassEnum[] values = S11ClassEnum.values(); |
| | | for (S11ClassEnum se : values) { |
| | | GoodsClass gc = new GoodsClass(); |
| | | gc.setKey(se.name()); |
| | | gc.setPicture(se.getIcon()); |
| | | gc.setName(se.getName()); |
| | | try { |
| | | gc.setUrl("http://ec-1255749512.file.myqcloud.com/resource/weex/flq_index_11_class.js?key=" + se.name() |
| | | + "&title=" + URLEncoder.encode(se.getName(), "UTF-8")); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | list.add(gc); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<RecommendBanner> getBanner() { |
| | | RecommendBanner recommendBanner = new RecommendBanner(); |
| | | recommendBanner.setPicture("http://ec-1255749512.file.myqcloud.com/resource/s11/class_banner.jpg"); |
| | | List<RecommendBanner> list = new ArrayList<>(); |
| | | list.add(recommendBanner); |
| | | return list; |
| | | } |
| | | |
| | | @Cacheable(value = "s11Cache", key = "'getPreSaleGoodsByType-'+#type+'-'+#page") |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> getPreSaleGoodsByType(String type, int page) { |
| | | String classIds = S11ClassEnum.valueOf(type).getTaoBaoClassIds(); |
| | | SearchFilter sf = new SearchFilter(); |
| | | sf.setCateIds(classIds); |
| | | // sf.setMaterialId("8440"); |
| | | sf.setKey("双11"); |
| | | sf.setEndPrice(new BigDecimal("220")); |
| | | sf.setQuan(1); |
| | | sf.setPage(page); |
| | | sf.setPageSize(Constant.PAGE_SIZE); |
| | | |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.S11PresaleGoodsType, type + "-" + page); |
| | | try { |
| | | String resultStr = redisManager.getCommonString(key); |
| | | if (!StringUtil.isNullOrEmpty(resultStr)) { |
| | | return new Gson().fromJson(resultStr, new TypeToken<List<TaoBaoGoodsBrief>>() { |
| | | }.getType()); |
| | | } |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | TaoBaoSearchResult result = TaoKeApiUtil.searchWuLiaoNew(sf,null,null); |
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) { |
| | | try { |
| | | redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 60);// 缓存1小时 |
| | | } catch (Exception e) { |
| | | } |
| | | return result.getTaoBaoGoodsBriefs(); |
| | | } else |
| | | return null; |
| | | } |
| | | |
| | | } |