admin
2019-08-12 6d933cb7a7345b8fc9fd51be52b79ec4cd837a13
增加品牌商品更新任务
2个文件已修改
46 ■■■■■ 已修改文件
fanli/src/main/java/com/yeshi/fanli/job/UpdateTaoBaoGoodsJob.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopGoodsServiceImpl.java 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
fanli/src/main/java/com/yeshi/fanli/job/UpdateTaoBaoGoodsJob.java
@@ -12,6 +12,7 @@
import com.yeshi.fanli.exception.ActivityException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.activity.ActivityService;
import com.yeshi.fanli.service.inter.brand.BrandClassShopGoodsService;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.lable.LabelService;
@@ -63,6 +64,9 @@
    @Resource
    private TLJBuyGoodsService tljBuyGoodsService;
    @Resource
    private BrandClassShopGoodsService brandClassShopGoodsService;
    // 动态商品更新 ,1个小时更新
    @Scheduled(cron = "0 0 */1 * * ?")
@@ -162,11 +166,19 @@
        }
    }
    // 更新品牌商品,每天早上6点执行一次
    // 更新增加品牌商品,每天早上6点执行一次
    @Scheduled(cron = "0 0 6 * * ? ")
    public void updateBrandGoods() {
    public void updateAddBrandGoods() {
        if (!Constant.IS_TASK)
            return;
        brandClassShopService.updateShopGoods();
    }
    // 更新原有精品库的品牌商品,每天凌晨3点执行一次
    @Scheduled(cron = "0 0 3 * * ? ")
    public void updateBrandGoods() {
        if (!Constant.IS_TASK)
            return;
        brandClassShopGoodsService.startUpdateGoods();
    }
}
fanli/src/main/java/com/yeshi/fanli/service/impl/brand/BrandClassShopGoodsServiceImpl.java
@@ -8,6 +8,7 @@
import com.yeshi.fanli.entity.brand.BrandClassShop;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.brand.BrandClassShopGoodsService;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
@@ -38,19 +39,24 @@
    @Override
    public void startUpdateGoods() {
        long count = brandClassShopService.countQuery(null, null, BrandClassShop.STATE_VALID);
        int page = (int) (count % 100 == 0 ? count / 100 : count / 100 + 1);
        int goodsCount = 0;
        try {
            long count = brandClassShopService.countQuery(null, null, BrandClassShop.STATE_VALID);
            int page = (int) (count % 100 == 0 ? count / 100 : count / 100 + 1);
        for (int i = 0; i < page; i++) {
            List<BrandClassShop> shopList = brandClassShopService.listQuery(i * 100, 100, null, null,
                    BrandClassShop.STATE_VALID);
            // 每个品牌最多更新100个商品
            if (shopList != null)
                for (BrandClassShop shop : shopList) {
                    Long sellerId = shop.getShop().getId();
                    List<TaoBaoGoodsBrief> goodsList = listBrandShopGoods(sellerId, 1, 100);
                    taoBaoGoodsUpdateService.addUpdateQueueAsync(goodsList);
                }
            for (int i = 0; i < page; i++) {
                List<BrandClassShop> shopList = brandClassShopService.listQuery(i * 100, 100, null, null,
                        BrandClassShop.STATE_VALID);
                // 每个品牌最多更新100个商品
                if (shopList != null)
                    for (BrandClassShop shop : shopList) {
                        Long sellerId = shop.getShop().getId();
                        List<TaoBaoGoodsBrief> goodsList = listBrandShopGoods(sellerId, 1, 100);
                        taoBaoGoodsUpdateService.addUpdateQueueAsync(goodsList);
                    }
            }
        } finally {
            LogHelper.test("品牌商品更新数量:" + goodsCount);
        }
    }