| | |
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.scheduling.annotation.Async;
|
| | | import org.springframework.stereotype.Service;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoGoodsBriefMapper;
|
| | | import com.yeshi.fanli.dao.taobao.TaoBaoGoodsUpdateDao;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.exception.goods.CommonGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsUpdateException;
|
| | | import com.yeshi.fanli.service.inter.activity.ActivityService;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.activity.ActivityGoodsUpdateService;
|
| | | import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
|
| | | import com.yeshi.fanli.service.inter.goods.RecommendSectionGoodsService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityFactoryGoodsUpdateService;
|
| | | import com.yeshi.fanli.service.inter.taobao.ShareHotGoodsService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TLJBuyGoodsUpdateService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
|
| | | import com.yeshi.fanli.util.BeanUtil;
|
| | | import com.yeshi.fanli.util.CMQManager;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
|
| | | import com.yeshi.fanli.util.factory.CommonGoodsFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | |
|
| | | @Service
|
| | | public class TaoBaoGoodsUpdateServiceImpl implements TaoBaoGoodsUpdateService {
|
| | | @Resource
|
| | | private RecommendSectionGoodsService recommendSectionGoodsService;
|
| | |
|
| | | @Resource
|
| | | private ActivityService activityService;
|
| | | private ActivityGoodsUpdateService activityGoodsUpdateService;
|
| | |
|
| | | @Resource
|
| | | private QualityFactoryService qualityFactoryService;
|
| | | private QualityFactoryGoodsUpdateService qualityFactoryGoodsUpdateService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper;
|
| | |
|
| | | @Resource
|
| | | private CommonGoodsService commonGoodsService;
|
| | |
|
| | | @Resource
|
| | | private ShareHotGoodsService shareHotGoodsService;
|
| | |
|
| | | @Resource
|
| | | private TLJBuyGoodsUpdateService tljBuyGoodsUpdateService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsUpdateDao taoBaoGoodsUpdateDao;
|
| | |
|
| | | @Override
|
| | | public void startUpdate() {
|
| | |
| | | @Transactional
|
| | | @Override
|
| | | public void deleteTaoBaoGoods(Long auctionId) {
|
| | | // 删除首页推荐数据
|
| | | recommendSectionGoodsService.deleteRecommendSectionGoodsByTbAuctionId(auctionId);
|
| | |
|
| | | // 删除精选库相关的数据
|
| | | qualityFactoryService.deleteByTbAuctionId(auctionId);
|
| | | qualityFactoryGoodsUpdateService.deleteByTaoBaoGoodsId(auctionId);
|
| | |
|
| | | // 删除商品本身数据
|
| | | taoBaoGoodsBriefMapper.deleteByAuctionId(auctionId);
|
| | |
| | | @Transactional
|
| | | @Override
|
| | | public void offlineTaoBaoGoods(Long auctionId) {
|
| | | // 删除首页推荐数据
|
| | | recommendSectionGoodsService.deleteRecommendSectionGoodsByTbAuctionId(auctionId);
|
| | | // 更新动态数据
|
| | | activityService.downTaoBaoGoods(auctionId);
|
| | | activityGoodsUpdateService.downTaoBaoGoods(auctionId);
|
| | |
|
| | | // 删除精选库相关的数据
|
| | | qualityFactoryService.deleteByTbAuctionId(auctionId);
|
| | | qualityFactoryGoodsUpdateService.deleteByTaoBaoGoodsId(auctionId);
|
| | |
|
| | | // 删除商品本身数据
|
| | | taoBaoGoodsBriefMapper.deleteByAuctionId(auctionId);
|
| | |
|
| | | // 更新简版商品状态为下架
|
| | | commonGoodsService.offlineCommonGoods(auctionId, CommonGoods.GOODS_TYPE_TB);
|
| | |
|
| | | // 分享爆款数据删除
|
| | | shareHotGoodsService.deleteByGoodsId(auctionId);
|
| | | }
|
| | |
|
| | | @Transactional
|
| | |
| | | if (goods.getAuctionId() == null || goods.getAuctionId() == 0)
|
| | | throw new TaobaoGoodsUpdateException(2, "商品ID为空");
|
| | |
|
| | | // 设置商品正常上线
|
| | | goods.setState(0);
|
| | | // 更新收藏信息
|
| | | try {
|
| | | commonGoodsService.updateCommonGoods(CommonGoodsFactory.create(goods));
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | List<TaoBaoGoodsBrief> goodsList = taoBaoGoodsBriefMapper.queryByAuctionId(goods.getAuctionId());
|
| | | if (goodsList != null)
|
| | | for (TaoBaoGoodsBrief tb : goodsList) {
|
| | | goods.setId(tb.getId());
|
| | | TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(goods);
|
| | | System.out.println("更细信息:" + new Gson().toJson(updateGoods));
|
| | | taoBaoGoodsBriefMapper.updateByPrimaryKeySelective(updateGoods);
|
| | |
|
| | | }
|
| | | TaoBaoGoodsBrief tb = taoBaoGoodsBriefMapper.selectByPrimaryKey(goods.getAuctionId());
|
| | | if (tb != null) {
|
| | | goods.setId(tb.getId());
|
| | | TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(goods);
|
| | | System.out.println("更细信息:" + new Gson().toJson(updateGoods));
|
| | | taoBaoGoodsBriefMapper.updateByPrimaryKeySelective(updateGoods);
|
| | | }
|
| | |
|
| | | // 更新动态商品
|
| | | activityService.updateRecommendActivityGoods(goods);
|
| | | activityGoodsUpdateService.updateRecommendActivityGoods(goods);
|
| | |
|
| | | // 更新分享库的商品
|
| | | shareHotGoodsService.updateShareGoods(goods);
|
| | |
|
| | | // 更新自购立减库商品
|
| | | tljBuyGoodsUpdateService.updateGoods(goods);
|
| | |
|
| | | // 总要商品更新
|
| | | updateImplTBGoods(goods);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void deleteOutOfDate() {
|
| | | TaoBaoGoodsBriefMapper taoBaoGoodsBriefMapper = BeanUtil.getBean(TaoBaoGoodsBriefMapper.class);
|
| | | List<Long> list = taoBaoGoodsBriefMapper
|
| | | .queryCanDeleteGoods(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 2), 0, 2000);
|
| | | for (Long auctionId : list) {
|
| | |
| | | updateGoods.setRootCategoryName(goods.getRootCategoryName());
|
| | | updateGoods.setLeafCatId(goods.getLeafCatId());
|
| | | updateGoods.setLeafName(goods.getLeafName());
|
| | | updateGoods.setMaterialLibType(goods.getMaterialLibType());
|
| | |
|
| | | return updateGoods;
|
| | | }
|
| | |
| | | List<TaoBaoGoodsBrief> updateList = new ArrayList<>();
|
| | |
|
| | | for (TaoBaoGoodsBrief goods : goodsList) {
|
| | |
|
| | | if (goods.getId() == null || goods.getId() == 0L) {
|
| | | throw new TaobaoGoodsUpdateException(1, "商品主键ID为空");
|
| | | }
|
| | |
|
| | | // 需要更新的信息
|
| | | TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(goods);
|
| | | updateGoods.setCreatetime(goods.getCreatetime());
|
| | |
|
| | | updateList.add(updateGoods);
|
| | | }
|
| | |
|
| | | taoBaoGoodsBriefMapper.updateBatchSelective(updateList);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<Long> listNeedUpdateGoodsId(long start, int count, int hour) {
|
| | | return taoBaoGoodsBriefMapper.listNeedUpdateGoodsId(start, count, hour);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void updateByTaoKeGoodsDetail(Long id) {
|
| | | try {
|
| | | TaoBaoGoodsBrief oldGoods = taoBaoGoodsBriefMapper.selectByPrimaryKey(id);
|
| | | if (oldGoods == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | TaoBaoGoodsBrief newGoods = TaoKeApiUtil.searchGoodsDetail(id);
|
| | | if (newGoods == null) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // 更新精选商品
|
| | | newGoods.setId(id);
|
| | | TaoBaoGoodsBrief updateGoods = getUpdateTaoBaoGoodsBrief(newGoods);
|
| | | taoBaoGoodsBriefMapper.updateByPrimaryKeySelective(updateGoods);
|
| | |
|
| | | // 更新动态商品
|
| | | activityGoodsUpdateService.updateRecommendActivityGoods(newGoods);
|
| | |
|
| | | // 更新收藏信息
|
| | | try {
|
| | | commonGoodsService.updateCommonGoods(CommonGoodsFactory.create(newGoods));
|
| | | } catch (CommonGoodsException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | offlineTaoBaoGoods(id);
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新重要的淘宝数据
|
| | | * |
| | | * @param goods
|
| | | */
|
| | | public void updateImplTBGoods(TaoBaoGoodsBrief goods) {
|
| | | if (goods == null)
|
| | | return;
|
| | | if (!taoBaoGoodsCacheUtil.needUpdate(goods.getAuctionId())) {
|
| | | return;
|
| | | }
|
| | | goods.setUpdatetime(new Date());
|
| | | taoBaoGoodsUpdateDao.save(goods);
|
| | | taoBaoGoodsCacheUtil.addUpdateHistory(goods.getAuctionId());
|
| | | }
|
| | |
|
| | | @Async
|
| | | @Override
|
| | | public void addUpdateQueueAsync(Long auctionId) {
|
| | | addUpdateQueueSync(auctionId);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 同步加入
|
| | | * |
| | | * @param auctionId
|
| | | */
|
| | | private void addUpdateQueueSync(Long auctionId) {
|
| | | try {
|
| | | if (taoBaoGoodsCacheUtil.canAddToUpdateQueue(auctionId)) {
|
| | | // 添加到更新队列
|
| | | CMQManager.getInstance().addTBImpGoodsUpdate(auctionId);
|
| | | taoBaoGoodsCacheUtil.addAddToQueueHistory(auctionId);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | @Async
|
| | | @Override
|
| | | public void addUpdateQueueAsync(List<TaoBaoGoodsBrief> goodsList) {
|
| | | if (goodsList != null)
|
| | | for (TaoBaoGoodsBrief goods : goodsList) {
|
| | | if (goods != null && goods.getAuctionId() != null)
|
| | | addUpdateQueueSync(goods.getAuctionId());
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public List<TaoBaoGoodsBrief> filterImportantTaoBaoGoods(List<TaoBaoGoodsBrief> goodsList) {
|
| | |
|
| | | // 商品过滤不允许出错
|
| | | try {
|
| | | Map<Long, TaoBaoGoodsBrief> finalMap = new HashMap<>();
|
| | | // 原始数据全覆盖
|
| | | for (TaoBaoGoodsBrief goods : goodsList) {
|
| | | finalMap.put(goods.getAuctionId(), goods);
|
| | | }
|
| | |
|
| | | List<TaoBaoGoodsBrief> tempGoodsList = new ArrayList<>();
|
| | | tempGoodsList.addAll(goodsList);
|
| | | // 先从redis里面取覆盖
|
| | | for (int i = 0; i < tempGoodsList.size(); i++) {
|
| | | TaoBaoGoodsBrief goods = taoBaoGoodsCacheUtil
|
| | | .getCommonTaoBaoGoodsInfo(tempGoodsList.get(i).getAuctionId());
|
| | | if (goods != null) {
|
| | | finalMap.put(goods.getAuctionId(), goods);
|
| | | tempGoodsList.remove(i--);
|
| | | }
|
| | | }
|
| | |
|
| | | // 再从mongodb中取覆盖
|
| | | List<Long> auctionIds = new ArrayList<>();
|
| | | for (TaoBaoGoodsBrief goods : tempGoodsList) {
|
| | | auctionIds.add(goods.getAuctionId());
|
| | | }
|
| | | List<TaoBaoGoodsBrief> mList = taoBaoGoodsUpdateDao.listByAuctionIds(auctionIds);
|
| | | if (mList != null)
|
| | | for (TaoBaoGoodsBrief goods : mList) {
|
| | | if (goods.getUpdatetime().getTime() > System.currentTimeMillis() - 1000 * 60 * 60 * 24L)// 在1天内更新的数据才参与过滤
|
| | | finalMap.put(goods.getAuctionId(), goods);
|
| | | }
|
| | |
|
| | | List<TaoBaoGoodsBrief> finalList = new ArrayList<>();
|
| | | for (TaoBaoGoodsBrief goods : goodsList) {
|
| | | TaoBaoGoodsBrief newGoods = finalMap.get(goods.getAuctionId());
|
| | | // 过滤价格,返利比例,券信息
|
| | | goods.setZkPrice(newGoods.getZkPrice());
|
| | | goods.setTkRate(newGoods.getTkRate());
|
| | | goods.setCouponAmount(newGoods.getCouponAmount());
|
| | | goods.setCouponActivityId(newGoods.getCouponActivityId());
|
| | | goods.setCouponEffectiveEndTime(newGoods.getCouponEffectiveEndTime());
|
| | | goods.setCouponEffectiveStartTime(newGoods.getCouponEffectiveStartTime());
|
| | | goods.setCouponStartFee(newGoods.getCouponStartFee());
|
| | | goods.setCouponTotalCount(newGoods.getCouponTotalCount());
|
| | | goods.setCouponLeftCount(newGoods.getCouponLeftCount());
|
| | |
|
| | | finalList.add(goods);
|
| | | }
|
| | | return finalList;
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | return goodsList;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public int listAndRemoveByMaxUpdateTime(Date maxTime, int page, int pageSize) {
|
| | | return taoBaoGoodsUpdateDao.listAndRemoveByMaxUpdateTime(maxTime, (page - 1) * pageSize, pageSize);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public long countByMaxUpdateTime(Date maxTime) {
|
| | | return taoBaoGoodsUpdateDao.countByMaxUpdateTime(maxTime);
|
| | |
|
| | | }
|
| | |
|
| | | }
|