admin
2020-05-19 744594ef1a2f530fc3e86ea9dc48b62247f79420
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
64
65
66
67
68
69
70
71
package com.yeshi.fanli.job;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
 
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.fanli.entity.brand.BrandInfo;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.brand.BrandInfoService;
import com.yeshi.fanli.util.Constant;
 
/**
 * 品牌信息更新
 * 
 * @author Administrator
 *
 */
@Component
public class BrandInfoJob {
 
    @Resource
    private BrandInfoService brandInfoService;
 
    /**
     * 每两个小时进行更新品牌商品信息
     */
    @XxlJob("brandGoodsUpdateHandler")
    public ReturnT<String> demoJobHandler(String param) throws Exception {
        updateGoods();
        return ReturnT.SUCCESS;
    }
 
    public void updateGoods() {
        System.out.println("品牌商品更新执行");
        if (!Constant.IS_TASK)
            return;
        long startTime = java.lang.System.currentTimeMillis();
        LogHelper.test("开始执行品牌更新---updateGoods" + startTime);
        long count = brandInfoService.countValidByCid(null);
        if (count == 0)
            return;
 
        List<BrandInfo> list = new ArrayList<>();
 
        long totalPage = (count / 100) + 1;
        for (long page = 0; page < totalPage; page++) {
            List<BrandInfo> tempList = brandInfoService.listValidOrderByUpdateTime((int) (page + 1), 100);
            if (tempList != null && tempList.size() > 0) {
                list.addAll(tempList);
            }
        }
 
        for (int page = 0; page < totalPage; page++) {
            try {
                brandInfoService.addShopAndGoods(
                        list.subList(page * 100, page * 100 + 100 > count ? (int) count : (page * 100 + 100)));
            } catch (Exception e) {
                LogHelper.errorDetailInfo(e);
            }
        }
 
        long endTime = java.lang.System.currentTimeMillis();
        LogHelper.test("结束执行品牌更新---updateGoods" + endTime + ",总耗时:" + (endTime - startTime) / 1000);
    }
 
}