yujian
2020-05-06 a4637ae9d71aa4a624b217ed3a1483f0e3a3a7ed
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package com.yeshi.fanli.util.cache;
 
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
import org.yeshi.utils.HttpUtil;
 
import com.yeshi.fanli.dto.common.CommonContentNav;
import com.yeshi.fanli.dto.common.CommonContentTypeEnum;
import com.yeshi.fanli.entity.brand.BrandClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.service.inter.brand.BrandClassService;
import com.yeshi.fanli.service.inter.goods.CommonTemplateContentService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.taobao.DaTaoKeUtil;
 
/**
 * 采用http请求触发商品缓存
 * 
 * @author Administrator
 *
 */
@Component
public class HttpGoodsCacheManager {
 
    @Resource
    private CommonTemplateContentService commonTemplateContentService;
 
    @Resource
    private GoodsClassService goodsClassService;
 
    @Resource
    private BrandClassService brandClassService;
 
    private static String getSign(Map<String, String> params) {
        List<String> list = new ArrayList<>();
        Iterator<String> its = params.keySet().iterator();
        while (its.hasNext()) {
            String key = its.next();
            Object value = params.get(key);
            list.add(key + "=" + value.toString());
        }
        Collections.sort(list);
        String str = "";
        for (String st : list) {
            str += st + "&";
        }
        String sign = null;
 
        sign = StringUtil.Md5(str + Constant.systemCommonConfig.getSignKey());
        return sign;
    }
 
    private void request(String url, Map<String, String> par) {
        Map<String, String> params = new HashMap<>();
        params.put("packages", "com.yeshi.ec.rebate");
        params.put("Version", "46");
        params.put("appkey", "24587154");
        params.put("platform", "android");
        params.put("apiversion", "1");
        params.put("channel", "GuanWang");
        params.put("imei", "862977040115210");
        params.put("osVersion", "8.0.0");
        params.put("network", "WIFI");
        params.put("deviceType", "LND-AL30");
        params.put("time", System.currentTimeMillis() + "");
        params.put("Device", "da105e2c-a7e8-3739-8fb8-4100da3c3aac");
 
        if (par != null) {
            for (Iterator<String> its = par.keySet().iterator(); its.hasNext();) {
                String key = its.next();
                params.put(key, par.get(key));
            }
        }
        params.put("time", System.currentTimeMillis() + "");
        params.put("sign", getSign(params));
        String result = HttpUtil.post(url, params, null);
        System.out.println(result);
    }
 
    // 触发首页的商品更新
    public void requestHomeRecommend() {
        Map<String, String> params = new HashMap<>();
        params.put("goodsType", 1 + "");
        for (int p = 1; p < 5; p++) {
            params.put("page", p + "");
            request("http://api.flqapp.com/fanli/api/v2/recommend/getGoodList", params);
        }
    }
 
    // 触发通用模板
    public void requestCommonTemplate() {
        CommonContentTypeEnum[] types = CommonContentTypeEnum.values();
        for (int p = 1; p < 3; p++) {
            for (CommonContentTypeEnum type : types) {
                List<CommonContentNav> navList = commonTemplateContentService.getNavList(type);
                if (navList != null && navList.size() > 0)
                    for (CommonContentNav nav : navList) {
                        commonTemplateContentService.getContentList(type, nav.getCid(), p, 50);
                    }
                else {
                    commonTemplateContentService.getContentList(type, null, p, 50);
                }
            }
        }
    }
 
    // 触发分类商品
    public void requestClassGoods() {
        Map<String, String> params = new HashMap<>();
        List<GoodsClass> classList = goodsClassService.getEffectiveClassCache();
        for (int p = 1; p < 3; p++) {
            params.put("page", p + "");
            for (GoodsClass gc : classList)
                params.put("gcid", gc.getId() + "");
            request("http://api.flqapp.com/fanli/api/v2/class/getClassGoods", params);
        }
    }
 
    // 触发动态
    public void requestDynamic() {
        // 热销
        List<GoodsClass> list = new ArrayList<GoodsClass>();
        list.add(new GoodsClass(0L, "今日单品"));
        list.addAll(DaTaoKeUtil.goodsClasses);
 
        for (int p = 1; p < 5; p++) {
            Map<String, String> params = new HashMap<>();
            params.put("cid", 1 + "");
            params.put("page", p + "");
            for (GoodsClass gc : list) {
                params.put("subId", gc.getId() + "");
                request("http://api.flqapp.com/fanli/api/v2/dynamic/getList", params);
            }
            // 推荐
            params = new HashMap<>();
            params.put("cid", 2 + "");
            params.put("page", p + "");
            request("http://api.flqapp.com/fanli/api/v2/dynamic/getList", params);
 
            // 好店
            params = new HashMap<>();
            params.put("cid", 3 + "");
            params.put("page", p + "");
            request("http://api.flqapp.com/fanli/api/v2/dynamic/getList", params);
        }
    }
 
    // 触发品牌商品列表
    public void requestBrandGoods() {
        List<BrandClass> list = brandClassService.listBrandClassEffectiveCache();
        list.add(new BrandClass(0L));
        list.addAll(list);
        for (int p = 1; p < 5; p++) {
            Map<String, String> params = new HashMap<>();
            params.put("page", p + "");
            for (BrandClass gc : list) {
                params.put("cid", gc.getId() + "");
                request("http://api.flqapp.com/fanli/api/v2/brand/getShopList", params);
            }
        }
 
    }
 
}