yujian
2019-03-20 1e53e5f28c55ece70b28c752fa318e2fd951e643
fanli/src/main/java/com/yeshi/fanli/controller/client/GoodsClassController.java
@@ -10,33 +10,28 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.clazz.ClassRecommendGoods;
import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSecondClass;
import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
import com.yeshi.fanli.entity.bus.su.clazz.SuperGoodsClass;
import com.yeshi.fanli.entity.system.System;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.taobao.SearchFilter;
import com.yeshi.fanli.entity.taobao.TaoBaoCoupon;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
import com.yeshi.fanli.exception.HongBaoManageException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.SystemService;
import com.yeshi.fanli.service.inter.goods.ClassRecommendGoodsService;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService;
import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
@@ -57,7 +52,9 @@
import com.yeshi.fanli.util.factory.MonitorFactory;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import org.yeshi.utils.JsonUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("api/v1/class")
@@ -68,9 +65,6 @@
   @Resource
   private GoodsSecondClassService goodsSecondClassService;
   @Resource
   private ClassRecommendGoodsService classRecommendGoodsService;
   @Resource
   private GoodsClassService goodsClassService;
@@ -88,7 +82,7 @@
   private HongBaoManageService manageService;
   @Resource
   private SystemService systemService;
   private BusinessSystemService businessSystemService;
   @Resource
   private RedisManager redisManager;
@@ -110,6 +104,9 @@
   @Resource
   private MonitorService monitorService;
   @Resource(name = "taskExecutor")
   private TaskExecutor executor;
   /**
    * 获取主类目
    * 
@@ -118,26 +115,34 @@
    */
   @RequestMapping(value = "getgoodsclass", method = RequestMethod.POST)
   public void getGoodsClass(AcceptData acceptData, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      try {
         BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
         if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
         }
         List<GoodsClass> goodsClassList = goodsClassService.getListClassCache(system.getId());
         if (goodsClassList == null || goodsClassList.size() == 0) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
            return;
         }
         JSONObject data = new JSONObject();
         data.put("count", goodsClassList.size());
         data.put("goodsClassList", goodsClassList);
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("获取失败"));
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      List<SuperGoodsClass> superGoodsClassList = superGoodsClassService.getSuperGoodsClassBySystemId(system.getId());
      if (superGoodsClassList == null || superGoodsClassList.size() == 0) {
         out.print(JsonUtil.loadFalseResult("暂无数据"));
         return;
      }
      List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
      for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
         GoodsClass goodsClass = superGoodsClass.getGoodsClass();
         goodsClassList.add(goodsClass);
      }
      JSONObject data = new JSONObject();
      data.put("count", goodsClassList.size());
      data.put("goodsClassList", goodsClassList);
      String result = JsonUtil.loadTrueResult(data);
      out.print(result);
   }
   /**
@@ -158,35 +163,38 @@
            return;
         }
         if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
            Long androidClick = goodsClass.getAndroidClick();
            if (androidClick != null) {
               goodsClass.setAndroidClick(androidClick + 1);
            } else {
               goodsClass.setAndroidClick(1L);
            }
         } else if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
            Long iosClick = goodsClass.getIosClick();
            if (iosClick != null) {
               goodsClass.setIosClick(iosClick + 1);
            } else {
               goodsClass.setIosClick(1L);
            }
         }
         goodsClassService.updateByPrimaryKeySelective(goodsClass);
         List<GoodsSubClass> goodsSubClassList = goodsSubClassService.getSubClassCache(gcid, 1);
         if (goodsSubClassList == null || goodsSubClassList.size() == 0) {
            out.print(JsonUtil.loadFalseResult("暂无数据"));
            return;
         if (goodsSubClassList == null) {
            goodsSubClassList = new ArrayList<GoodsSubClass>();
         }
         JSONObject data = new JSONObject();
         data.put("count", goodsSubClassList.size());
         data.put("goodsSecondClassList", JsonUtil.getApiCommonGson().toJson(goodsSubClassList));
         out.print(JsonUtil.loadTrueResult(data));
         // 更新分类点击次数
         executor.execute(new Runnable() {
            @Override
            public void run() {
               if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
                  Long androidClick = goodsClass.getAndroidClick();
                  if (androidClick != null) {
                     goodsClass.setAndroidClick(androidClick + 1);
                  } else {
                     goodsClass.setAndroidClick(1L);
                  }
               } else if ("ios".equalsIgnoreCase(acceptData.getPlatform())) {
                  Long iosClick = goodsClass.getIosClick();
                  if (iosClick != null) {
                     goodsClass.setIosClick(iosClick + 1);
                  } else {
                     goodsClass.setIosClick(1L);
                  }
               }
               goodsClassService.updateByPrimaryKeySelective(goodsClass);
            }
         });
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("暂无数据"));
@@ -199,20 +207,6 @@
   }
   @RequestMapping(value = "getclassrecommendgoods", method = RequestMethod.POST)
   public void getClassRecommendGoods(AcceptData acceptData, long goodsClassId, PrintWriter out) {
      List<ClassRecommendGoods> classRecommendGoodsList = classRecommendGoodsService
            .getClassRecommendGoodsByGoodsClassId(goodsClassId);
      if (classRecommendGoodsList == null) {
         out.print(JsonUtil.loadFalseResult("暂无数据"));
         return;
      }
      JSONObject data = new JSONObject();
      data.put("count", classRecommendGoodsList.size());
      data.put("classRecommendGoodsList", JsonUtil.getApiCommonGson().toJson(classRecommendGoodsList));
      String result = JsonUtil.loadTrueResult(data);
      out.print(result);
   }
   @RequestMapping(value = "getCouponGoods", method = RequestMethod.POST)
   public void getCouponGoods(AcceptData acceptData, int page, long gcid, PrintWriter out) {
@@ -263,7 +257,7 @@
   @RequestMapping(value = "getgoods", method = RequestMethod.POST)
   public void getGoods(AcceptData acceptData, int page, long scid, String filter, String order, String startprice,
         String endprice, String fastFilter, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -371,7 +365,7 @@
   @RequestMapping(value = "getsecondclassgoods", method = RequestMethod.POST)
   public void getSecondClassGoods(AcceptData acceptData, int page, long scid, String filter, String order,
         String startprice, String endprice, String fastFilter, Integer totalSales, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -515,8 +509,8 @@
            // 设置SearchFilter
            taoKeGoodsService.setSearchFilter(searchfilter, filter, order, startprice, endprice, fastFilter,
                  totalSales);
            // 用户未输入最高价格时    最高价格限制99999
            // 用户未输入最高价格时 最高价格限制99999
            if (searchfilter.getEndPrice() == null) {
               searchfilter.setEndPrice(new BigDecimal(99999));
            }
@@ -545,7 +539,7 @@
   @RequestMapping("choiceGoods")
   public void choiceGoods(AcceptData acceptData, long gcid, int page, PrintWriter out) {
      System system = systemService.getSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(), acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
@@ -628,6 +622,11 @@
         } else {
            taoBaoGoodsBrief.setSalesCount(biz30day + "");
         }
         // 白底图测试
         // if
         // (!StringUtil.isNullOrEmpty(taoBaoGoodsBrief.getPictUrlWhite()))
         // taoBaoGoodsBrief.setPictUrl(taoBaoGoodsBrief.getPictUrlWhite());
         array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
      }
@@ -798,10 +797,10 @@
    */
   private void setTaoBaoCouponHongBao(List<TaoBaoCoupon> taoBaoCoupons) {
      if (taoBaoCoupons.size() > 0) {
         BigDecimal proportion= hongBaoManageService.getFanLiRate();
         BigDecimal proportion = hongBaoManageService.getFanLiRate();
         for (TaoBaoCoupon taoBaoCoupon : taoBaoCoupons) {
            BigDecimal hb = TaoBaoUtil.getCouponHongBaoInfo(taoBaoCoupon,proportion);
            BigDecimal hb = TaoBaoUtil.getCouponHongBaoInfo(taoBaoCoupon, proportion);
            taoBaoCoupon.setHongbao(hb);
         }
      }
@@ -809,59 +808,31 @@
   @RequestMapping(value = { "getcategory" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST })
   public void getcategory(AcceptData acceptData, PrintWriter out) {
      com.yeshi.fanli.entity.system.System system = this.systemService.getSystemCache(acceptData.getPlatform(),
            acceptData.getPackages());
      if (system == null) {
         out.print(JsonUtil.loadFalseResult("系统不存在"));
         return;
      }
      try {
         com.yeshi.fanli.entity.system.BusinessSystem system = this.businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
               acceptData.getPackages());
         if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
         }
      List<SuperGoodsClass> superGoodsClassList = this.superGoodsClassService
            .getSuperGoodsClassBySystemId(system.getId().longValue());
      if ((superGoodsClassList == null) || (superGoodsClassList.size() == 0)) {
         out.print(JsonUtil.loadFalseResult("暂无数据"));
         return;
      }
         List<Map<String, Object>> listCache = goodsClassService.getClassListAllCache(system.getId());
         if (listCache == null) {
            listCache = new ArrayList<Map<String, Object>>();
         }
      List<GoodsClass> goodsClassList = new ArrayList<GoodsClass>();
      for (SuperGoodsClass superGoodsClass : superGoodsClassList) {
         GoodsClass goodsClass = superGoodsClass.getGoodsClass();
         goodsClassList.add(goodsClass);
      }
         JSONObject data = new JSONObject();
         data.put("categoryList", listCache);
      JSONArray array = new JSONArray();
         out.print(JsonUtil.loadTrueResult(data));
      Gson gson = new GsonBuilder().create();
      if (goodsClassList.size() > 0) {
         for (GoodsClass goodsClass : goodsClassList) {
            goodsClass.setKey(null);
            goodsClass.setCreatetime(0L);
            goodsClass.setSearchParam(null);
            goodsClass.setIosClick(null);
            goodsClass.setAndroidClick(null);
            JSONObject data = new JSONObject();
            data.put("gclass", goodsClass);
            long gcid = goodsClass.getId();
            try {
               List<GoodsSubClass> subClassList = this.goodsSubClassService.getSubClassCache(Long.valueOf(gcid),
                     Integer.valueOf(1));
               if ((subClassList == null) || (subClassList.size() == 0)) {
                  subClassList = new ArrayList<GoodsSubClass>();
               }
               data.put("subList", gson.toJson(subClassList));
            } catch (Exception e) {
               e.printStackTrace();
            }
            array.add(data);
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("获取失败"));
         try {
            LogHelper.errorDetailInfo(e);
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      }
      JSONObject data = new JSONObject();
      data.put("categoryList", array);
      out.print(JsonUtil.loadTrueResult(data));
   }
}