admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
fanli/src/main/java/com/yeshi/fanli/util/cache/HttpGoodsCacheManager.java
@@ -1,174 +1,175 @@
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(null);
      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);
         }
      }
   }
}
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 com.yeshi.fanli.entity.SystemEnum;
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,SystemEnum.blks);
            if (navList != null && navList.size() > 0)
               for (CommonContentNav nav : navList) {
                  commonTemplateContentService.getContentList(type, nav.getCid(), p, 50, SystemEnum.blks);
               }
            else {
               commonTemplateContentService.getContentList(type, null, p, 50, SystemEnum.blks);
            }
         }
      }
   }
   // 触发分类商品
   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(null);
      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);
         }
      }
   }
}