| | |
| | | package com.yeshi.fanli.service.impl.taobao;
|
| | |
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Comparator;
|
| | | import java.util.Date;
|
| | | 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.cache.ehcache.EhCacheCacheManager;
|
| | | import org.springframework.stereotype.Service;
|
| | |
|
| | | import com.yeshi.fanli.dao.taobao.TLJFreeBuyGoodsDao;
|
| | | import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
|
| | | import com.yeshi.fanli.entity.taobao.TLJFreeBuyGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TLJFreeBuyGoodsService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
|
| | | import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
|
| | | import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailV2Service;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TaoBaoConstant;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
|
| | | @Service
|
| | | public class TLJFreeBuyGoodsServiceImpl implements TLJFreeBuyGoodsService {
|
| | | @Resource
|
| | | private TLJFreeBuyGoodsDao tljFreeBuyGoodsDao;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
| | | |
| | | @Resource
|
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
| | |
|
| | | @Resource
|
| | | private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
|
| | | |
| | | @Resource
|
| | | private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service;
|
| | | |
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private EhCacheCacheManager ehCacheCacheManager;
|
| | | |
| | |
|
| | | @Override
|
| | | public void addGoods(TLJFreeBuyGoods goods) {
|
| | | if (goods == null || StringUtil.isNullOrEmpty(goods.getDay()) || goods.getGoods() == null)
|
| | | return;
|
| | | goods.setId(StringUtil.Md5(goods.getDay() + "#" + goods.getGoods().getAuctionId()));
|
| | | |
| | | if (goods.getWeight() == null)
|
| | | goods.setWeight(1);
|
| | | |
| | | if (goods.getUpdateTime() == null)
|
| | | goods.setUpdateTime(new Date());
|
| | | tljFreeBuyGoodsDao.save(goods);
|
| | | }
|
| | |
|
| | | |
| | | //@Cacheable(value = "commonContentCache", key = "'tljFreeBuy-listByDay'+#day")
|
| | | @Override
|
| | | public List<TLJFreeBuyGoods> listByDay(String day) {
|
| | | List<TLJFreeBuyGoods> list = listByDay(day, 10);
|
| | | if (list != null)
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | // 过滤淘礼金大于10块钱的
|
| | | BigDecimal hongBao = TaoBaoUtil.getGoodsHongBaoMoney(list.get(i).getGoods(),
|
| | | TaoBaoConstant.OWN_BUY_WITHOUT_FANLI_RATE);
|
| | | if (hongBao.compareTo(new BigDecimal(10)) > 0) {
|
| | | list.remove(i--);
|
| | | }
|
| | | }
|
| | |
|
| | | List<TLJFreeBuyGoods> goodsList = new ArrayList<>();
|
| | | if (list != null && list.size() > 0)
|
| | | goodsList.addAll(list);
|
| | | |
| | | Collections.shuffle(goodsList);
|
| | | Comparator<TLJFreeBuyGoods> cm = new Comparator<TLJFreeBuyGoods>() {
|
| | | @Override
|
| | | public int compare(TLJFreeBuyGoods o1, TLJFreeBuyGoods o2) {
|
| | | return o1.getWeight() != null && o2.getWeight() != null ? o2.getWeight() - o1.getWeight() : 0;
|
| | | }
|
| | | };
|
| | | Collections.sort(goodsList, cm);
|
| | | return goodsList;
|
| | | }
|
| | |
|
| | | |
| | | @Override
|
| | | public List<TLJFreeBuyGoods> listByDay(String day, int count) {
|
| | | List<TLJFreeBuyGoods> list = tljFreeBuyGoodsDao.listByDay(day, 1, count);
|
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
|
| | | if (list != null) {
|
| | | for (TLJFreeBuyGoods shg : list)
|
| | | goodsList.add(shg.getGoods());
|
| | | }
|
| | | // 过滤基本商品信息
|
| | | goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList);
|
| | | // 过滤下线商品
|
| | | goodsList = taoBaoGoodsBriefService.filterOffLineGoods(goodsList);
|
| | | // 添加大淘客信息
|
| | | goodsList = daTaoKeGoodsDetailService.filterTaoBaoGoods(goodsList);
|
| | | |
| | | Map<Long, TaoBaoGoodsBrief> goodsMap = new HashMap<>();
|
| | | if (goodsList != null)
|
| | | for (TaoBaoGoodsBrief g : goodsList)
|
| | | goodsMap.put(g.getAuctionId(), g);
|
| | |
|
| | | for (int j = 0; j < list.size(); j++) {
|
| | | if (goodsMap.get(list.get(j).getGoods().getAuctionId()) == null) {
|
| | | list.remove(j);
|
| | | j--;
|
| | | }
|
| | | }
|
| | |
|
| | | // 加入更新队列
|
| | | //
|
| | | try {
|
| | | for (TLJFreeBuyGoods tljGoods : list)
|
| | | if (tljGoods != null && tljGoods.getGoods() != null && tljGoods.getGoods().getAuctionId() != null)
|
| | | taoBaoGoodsUpdateService.addUpdateQueueAsync(tljGoods.getGoods().getAuctionId());
|
| | | } catch (Exception e) {
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public void deleteById(String id) {
|
| | | tljFreeBuyGoodsDao.delete(id);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteByGoodsId(Long auctionId) {
|
| | | tljFreeBuyGoodsDao.deleteByGoodsId(auctionId);
|
| | | // 清除列表缓存
|
| | | ehCacheCacheManager.getCache("commonContentCache")
|
| | | .evict("TLJFreeBuy-listByDay" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd"));
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public TLJFreeBuyGoods selectByAuctionIdAndDay(Long auctionId, String day) {
|
| | | return tljFreeBuyGoodsDao.selectByAuctionIdAndDay(auctionId, day);
|
| | | }
|
| | | |
| | | |
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> listPreGoods(String key ,int page) {
|
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>();
|
| | | // 大淘客筛选: 券后价 1-2区间 、综合排序
|
| | | DaTaoKeGoodsResult result = DaTaoKeApiUtil.search(key, null, new BigDecimal(1), new BigDecimal(2), 1, page, 100, 0);
|
| | | if (result != null && result.getGoodsList() != null) {
|
| | | for (DaTaoKeDetailV2 v2 : result.getGoodsList())
|
| | | goodsList.add(TaoBaoUtil.convert(v2));
|
| | | }
|
| | | return goodsList;
|
| | | }
|
| | |
|
| | |
|
| | | package com.yeshi.fanli.service.impl.taobao; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Comparator; |
| | | import java.util.Date; |
| | | 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.cache.ehcache.EhCacheCacheManager; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import com.yeshi.fanli.dao.taobao.TLJFreeBuyGoodsDao; |
| | | import com.yeshi.goods.facade.dto.taobao.dataoke.DaTaoKeGoodsResult; |
| | | import com.yeshi.fanli.entity.taobao.TLJFreeBuyGoods; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.goods.facade.entity.taobao.dataoke.DaTaoKeDetailV2; |
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; |
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; |
| | | import com.yeshi.fanli.service.inter.taobao.TLJFreeBuyGoodsService; |
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService; |
| | | import com.yeshi.goods.facade.service.DaTaoKeGoodsDetailV2Service; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.TaoBaoConstant; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import com.yeshi.goods.facade.utils.taobao.DaTaoKeApiUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | |
| | | @Service |
| | | public class TLJFreeBuyGoodsServiceImpl implements TLJFreeBuyGoodsService { |
| | | @Resource |
| | | private TLJFreeBuyGoodsDao tljFreeBuyGoodsDao; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsBriefService taoBaoGoodsBriefService; |
| | | |
| | | @Resource |
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService; |
| | | |
| | | |
| | | @Resource |
| | | private DaTaoKeGoodsDetailV2Service daTaoKeGoodsDetailV2Service; |
| | | |
| | | @Resource |
| | | private HongBaoManageService hongBaoManageService; |
| | | |
| | | @Resource |
| | | private EhCacheCacheManager ehCacheCacheManager; |
| | | |
| | | |
| | | @Override |
| | | public void addGoods(TLJFreeBuyGoods goods) { |
| | | if (goods == null || StringUtil.isNullOrEmpty(goods.getDay()) || goods.getGoods() == null) |
| | | return; |
| | | goods.setId(StringUtil.Md5(goods.getDay() + "#" + goods.getGoods().getAuctionId())); |
| | | |
| | | if (goods.getWeight() == null) |
| | | goods.setWeight(1); |
| | | |
| | | if (goods.getUpdateTime() == null) |
| | | goods.setUpdateTime(new Date()); |
| | | tljFreeBuyGoodsDao.save(goods); |
| | | } |
| | | |
| | | |
| | | @Cacheable(value = "commonContentCache", key = "'tljFreeBuy-listByDay'+#day") |
| | | @Override |
| | | public List<TLJFreeBuyGoods> listByDay(String day) { |
| | | List<TLJFreeBuyGoods> list = listByDay(day, 10); |
| | | if (list != null) |
| | | for (int i = 0; i < list.size(); i++) { |
| | | // 过滤淘礼金大于10块钱的 |
| | | BigDecimal hongBao = TaoBaoUtil.getGoodsHongBaoMoney(list.get(i).getGoods(), |
| | | TaoBaoConstant.OWN_BUY_WITHOUT_FANLI_RATE,false); |
| | | if (hongBao.compareTo(new BigDecimal(10)) > 0) { |
| | | list.remove(i--); |
| | | } |
| | | } |
| | | |
| | | List<TLJFreeBuyGoods> goodsList = new ArrayList<>(); |
| | | if (list != null && list.size() > 0) |
| | | goodsList.addAll(list); |
| | | |
| | | Collections.shuffle(goodsList); |
| | | Comparator<TLJFreeBuyGoods> cm = new Comparator<TLJFreeBuyGoods>() { |
| | | @Override |
| | | public int compare(TLJFreeBuyGoods o1, TLJFreeBuyGoods o2) { |
| | | return o1.getWeight() != null && o2.getWeight() != null ? o2.getWeight() - o1.getWeight() : 0; |
| | | } |
| | | }; |
| | | Collections.sort(goodsList, cm); |
| | | return goodsList; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<TLJFreeBuyGoods> listByDay(String day, int count) { |
| | | List<TLJFreeBuyGoods> list = tljFreeBuyGoodsDao.listByDay(day, 1, count); |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | if (list != null) { |
| | | for (TLJFreeBuyGoods shg : list) |
| | | goodsList.add(shg.getGoods()); |
| | | } |
| | | // 过滤基本商品信息 |
| | | goodsList = taoBaoGoodsUpdateService.filterImportantTaoBaoGoods(goodsList); |
| | | // 过滤下线商品 |
| | | goodsList = taoBaoGoodsBriefService.filterOffLineGoods(goodsList); |
| | | // 添加大淘客信息 |
| | | goodsList = daTaoKeGoodsDetailV2Service.filterTaoBaoGoods(goodsList); |
| | | |
| | | Map<String, TaoBaoGoodsBrief> goodsMap = new HashMap<>(); |
| | | if (goodsList != null) |
| | | for (TaoBaoGoodsBrief g : goodsList) |
| | | goodsMap.put(g.getAuctionId(), g); |
| | | |
| | | for (int j = 0; j < list.size(); j++) { |
| | | if (goodsMap.get(list.get(j).getGoods().getAuctionId()) == null) { |
| | | list.remove(j); |
| | | j--; |
| | | } |
| | | } |
| | | |
| | | // 加入更新队列 |
| | | // |
| | | try { |
| | | for (TLJFreeBuyGoods tljGoods : list) |
| | | if (tljGoods != null && tljGoods.getGoods() != null && tljGoods.getGoods().getAuctionId() != null) |
| | | taoBaoGoodsUpdateService.addUpdateQueueAsync(tljGoods.getGoods().getAuctionId()); |
| | | } catch (Exception e) { |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void deleteById(String id) { |
| | | tljFreeBuyGoodsDao.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteByGoodsId(String auctionId) { |
| | | tljFreeBuyGoodsDao.deleteByGoodsId(auctionId); |
| | | // 清除列表缓存 |
| | | ehCacheCacheManager.getCache("commonContentCache") |
| | | .evict("TLJFreeBuy-listByDay" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyy-MM-dd")); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public TLJFreeBuyGoods selectByAuctionIdAndDay(String auctionId, String day) { |
| | | return tljFreeBuyGoodsDao.selectByAuctionIdAndDay(auctionId, day); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<TaoBaoGoodsBrief> listPreGoods(String key ,int page) { |
| | | List<TaoBaoGoodsBrief> goodsList = new ArrayList<>(); |
| | | // 大淘客筛选: 券后价 1-2区间 、综合排序 |
| | | // DaTaoKeGoodsResult result = DaTaoKeApiUtil.search(key, null, new BigDecimal(1), new BigDecimal(2), 1, page, 100, 0); |
| | | DaTaoKeGoodsResult result = DaTaoKeApiUtil.getGoodsList(key, null, new BigDecimal(1), new BigDecimal(2), 1, page, 100, 0); |
| | | |
| | | |
| | | if (result != null && result.getGoodsList() != null) { |
| | | for (DaTaoKeDetailV2 v2 : result.getGoodsList()) |
| | | goodsList.add(TaoBaoUtil.convert(v2)); |
| | | } |
| | | return goodsList; |
| | | } |
| | | |
| | | |
| | | } |