admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.yeshi.fanli.service.impl.brand;
 
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.entity.brand.BrandClassShop;
import com.yeshi.goods.facade.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;
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
 
@Service
public class BrandClassShopGoodsServiceImpl implements BrandClassShopGoodsService {
 
    @Resource
    private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
 
    @Resource
    private BrandClassShopService brandClassShopService;
 
    @Resource
    private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
 
    @Override
    public List<TaoBaoGoodsBrief> listBrandShopGoods(Long sellerId, int page, int count) {
 
        return taoBaoGoodsBriefService.listByShopId((page - 1) * count, count, sellerId);
    }
 
    @Override
    public long countBrandShopGoods(Long sellerId) {
        return taoBaoGoodsBriefService.countByShopId(sellerId);
    }
 
    @Override
    public void startUpdateGoods() {
        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);
                    }
            }
        } finally {
            LogHelper.test("品牌商品更新数量:" + goodsCount);
        }
    }
 
}