| | |
| | | package com.yeshi.fanli.service.impl.goods;
|
| | |
|
| | | import java.lang.reflect.Type;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.cache.annotation.Cacheable;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoCouponMapper;
|
| | | import com.yeshi.fanli.entity.taobao.PidUser;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
| | | 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.TaoBaoCouponUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | @Service
|
| | | public class TaoBaoCouponServiceImpl implements TaoBaoCouponService {
|
| | |
|
| | | @Resource
|
| | | private TaoBaoCouponMapper taoBaoCouponMapper;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Transactional
|
| | | @Override
|
| | | public void updateTaoBaoCoupon() {
|
| | | List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
| | |
|
| | | Set<TaoBaoCoupon> taoBaoCouponList = TaoBaoCouponUtil.getTaoBaoCouponList(config.get(0));
|
| | | if (taoBaoCouponList == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | List<TaoBaoCoupon> list = new ArrayList<>();
|
| | | for (TaoBaoCoupon taoBaoCoupon : taoBaoCouponList) {
|
| | | list.add(taoBaoCoupon);
|
| | | }
|
| | |
|
| | | // 随机排序
|
| | | if (list != null)
|
| | | Collections.shuffle(list);
|
| | | long minId = 1;
|
| | | int ii = 0;
|
| | | for (TaoBaoCoupon taoBaoCoupon : list) {
|
| | | if (ii == 0) {
|
| | | taoBaoCouponMapper.insert(taoBaoCoupon);
|
| | | minId = taoBaoCoupon.getId();
|
| | | } else {
|
| | | taoBaoCouponMapper.insert(taoBaoCoupon);
|
| | | }
|
| | | ii++;
|
| | | }
|
| | | |
| | | taoBaoCouponMapper.deleteBeforeCouponInfo(minId);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TaoBaoCoupon> getTaoBaoCouponList(String key, int page) {
|
| | | return taoBaoCouponMapper.getTaoBaoCouponList((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int getCount(String key) {
|
| | | return taoBaoCouponMapper.getCount(key);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TaoBaoCoupon> getTaoBaoCouponListBykeys(List<String> searchKeys, int page) {
|
| | |
|
| | | if (searchKeys != null && searchKeys.size() == 0) {
|
| | | searchKeys = null;
|
| | | }
|
| | | |
| | | return taoBaoCouponMapper.getTaoBaoCouponListBykeys((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE,searchKeys);
|
| | | }
|
| | | |
| | | @Override
|
| | | public int getCount(List<String> searchKeys) {
|
| | | if (searchKeys != null && searchKeys.size() == 0) {
|
| | | searchKeys = null;
|
| | | }
|
| | | return taoBaoCouponMapper.countTaoBaoCouponListBykeys(searchKeys);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public TaoBaoCoupon getTaoBaoCouponByActionId(String auctionId) {
|
| | | return taoBaoCouponMapper.getTaoBaoCouponByActionId(auctionId);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 采用redis做缓存
|
| | | */
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> getTaoBaoCouponList(int page) {
|
| | | System.out.println("进入了方法");
|
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCachecoupon, page +"");
|
| | | String resultStr = "";
|
| | | try {
|
| | | resultStr = redisManager.getCommonString(key);
|
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(resultStr)) {
|
| | | Type type = new TypeToken<List<TaoBaoGoodsBrief>>() {
|
| | | }.getType();
|
| | | List<TaoBaoGoodsBrief> list = new Gson().fromJson(resultStr, type);
|
| | | return list;
|
| | | }
|
| | |
|
| | | TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(3756, page, 20);// searchCouple(null,
|
| | | // null,
|
| | | // page,
|
| | | // 20);
|
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
|
| | | // 20分钟缓存
|
| | | try {
|
| | | redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 20);
|
| | | } catch (Exception e) {
|
| | | }
|
| | |
|
| | | return result.getTaoBaoGoodsBriefs();
|
| | | }
|
| | |
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Cacheable(value = "taoBaoCouponCache", key = "'getTaoBaoCouponListByMeterialId'+#materialId+'-'+#page")
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> getTaoBaoCouponListByMeterialId(int materialId, int page) {
|
| | | TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(materialId, page, 20);
|
| | | if (result != null)
|
| | | return result.getTaoBaoGoodsBriefs();
|
| | | return null;
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.service.impl.goods; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoCouponMapper; |
| | | import com.yeshi.fanli.entity.taobao.PidUser; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoCoupon; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig; |
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; |
| | | 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.TaoBaoCouponUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil; |
| | | |
| | | @Service |
| | | public class TaoBaoCouponServiceImpl implements TaoBaoCouponService { |
| | | |
| | | @Resource |
| | | private TaoBaoCouponMapper taoBaoCouponMapper; |
| | | |
| | | @Resource |
| | | private TaoBaoUnionConfigService taoBaoUnionConfigService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void updateTaoBaoCoupon() { |
| | | List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID); |
| | | |
| | | Set<TaoBaoCoupon> taoBaoCouponList = TaoBaoCouponUtil.getTaoBaoCouponList(config.get(0)); |
| | | if (taoBaoCouponList == null) { |
| | | return; |
| | | } |
| | | |
| | | List<TaoBaoCoupon> list = new ArrayList<>(); |
| | | for (TaoBaoCoupon taoBaoCoupon : taoBaoCouponList) { |
| | | list.add(taoBaoCoupon); |
| | | } |
| | | |
| | | // 随机排序 |
| | | if (list != null) |
| | | Collections.shuffle(list); |
| | | long minId = 1; |
| | | int ii = 0; |
| | | for (TaoBaoCoupon taoBaoCoupon : list) { |
| | | if (ii == 0) { |
| | | taoBaoCouponMapper.insert(taoBaoCoupon); |
| | | minId = taoBaoCoupon.getId(); |
| | | } else { |
| | | taoBaoCouponMapper.insert(taoBaoCoupon); |
| | | } |
| | | ii++; |
| | | } |
| | | |
| | | taoBaoCouponMapper.deleteBeforeCouponInfo(minId); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaoBaoCoupon> getTaoBaoCouponList(String key, int page) { |
| | | return taoBaoCouponMapper.getTaoBaoCouponList((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE, key); |
| | | } |
| | | |
| | | @Override |
| | | public int getCount(String key) { |
| | | return taoBaoCouponMapper.getCount(key); |
| | | } |
| | | |
| | | @Override |
| | | public List<TaoBaoCoupon> getTaoBaoCouponListBykeys(List<String> searchKeys, int page) { |
| | | |
| | | if (searchKeys != null && searchKeys.size() == 0) { |
| | | searchKeys = null; |
| | | } |
| | | |
| | | return taoBaoCouponMapper.getTaoBaoCouponListBykeys((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE,searchKeys); |
| | | } |
| | | |
| | | @Override |
| | | public int getCount(List<String> searchKeys) { |
| | | if (searchKeys != null && searchKeys.size() == 0) { |
| | | searchKeys = null; |
| | | } |
| | | return taoBaoCouponMapper.countTaoBaoCouponListBykeys(searchKeys); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public TaoBaoCoupon getTaoBaoCouponByActionId(String auctionId) { |
| | | return taoBaoCouponMapper.getTaoBaoCouponByActionId(auctionId); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 采用redis做缓存 |
| | | */ |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> getTaoBaoCouponList(int page) { |
| | | System.out.println("进入了方法"); |
| | | String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.taobaoCachecoupon, page +""); |
| | | String resultStr = ""; |
| | | try { |
| | | resultStr = redisManager.getCommonString(key); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(resultStr)) { |
| | | Type type = new TypeToken<List<TaoBaoGoodsBrief>>() { |
| | | }.getType(); |
| | | List<TaoBaoGoodsBrief> list = new Gson().fromJson(resultStr, type); |
| | | return list; |
| | | } |
| | | |
| | | TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(3756, page, 20);// searchCouple(null, |
| | | // null, |
| | | // page, |
| | | // 20); |
| | | if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) { |
| | | // 20分钟缓存 |
| | | try { |
| | | redisManager.cacheCommonString(key, new Gson().toJson(result.getTaoBaoGoodsBriefs()), 60 * 20); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | return result.getTaoBaoGoodsBriefs(); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | |
| | | @Cacheable(value = "taoBaoCouponCache", key = "'getTaoBaoCouponListByMeterialId'+#materialId+'-'+#page") |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> getTaoBaoCouponListByMeterialId(int materialId, int page) { |
| | | TaoBaoSearchResult result = TaoKeApiUtil.getMaterialByMaterialId(materialId, page, 20); |
| | | if (result != null) |
| | | return result.getTaoBaoGoodsBriefs(); |
| | | return null; |
| | | } |
| | | |
| | | } |