admin
2019-05-15 3be3f6e670d2e11d7ced76b8202f0ef30b56870f
fanli/src/main/java/com/yeshi/fanli/controller/client/BrandController.java
@@ -18,7 +18,6 @@
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.brand.BrandClass;
import com.yeshi.fanli.entity.brand.TaoBaoShopHistory;
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.entity.taobao.TaoBaoShop;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
@@ -26,11 +25,12 @@
import com.yeshi.fanli.service.inter.brand.BrandClassService;
import com.yeshi.fanli.service.inter.brand.BrandClassShopService;
import com.yeshi.fanli.service.inter.brand.TaoBaoShopHistoryService;
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoShopService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
@@ -56,8 +56,9 @@
   @Resource
   private HongBaoManageService manageService;
   @Resource
   private QualityGoodsService qualityGoodsService;
   private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
   /**
    * 获取品牌分类
@@ -84,26 +85,6 @@
      }
   }
   /**
    * 添加足迹
    *
    * @param acceptData
    * @param out
    */
   @RequestMapping(value = "addHistory", method = RequestMethod.POST)
   public void addHistory(AcceptData acceptData, Long sid, Long uid, PrintWriter out) {
      try {
         if (sid == null || sid == 0) {
            out.print(JsonUtil.loadFalseResult("店铺id为空"));
            return;
         }
         taoBaoShopHistoryService.addHistory(sid, uid, acceptData.getDevice());
         out.print(JsonUtil.loadTrueResult("记录成功"));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("记录失败"));
         e.printStackTrace();
      }
   }
   /**
@@ -137,6 +118,15 @@
   @RequestMapping(value = "getHistory", method = RequestMethod.POST)
   public void getHistory(AcceptData acceptData, Integer page, Long uid, Integer type, PrintWriter out) {
      try {
         if (type == null) {
            out.print(JsonUtil.loadFalseResult("类型不正确"));
            return;
         }
         if (page == null || page < 1) {
            page = 1;
         }
         int pageSize;
         if (type == 1) {
            pageSize = 4;
@@ -164,13 +154,29 @@
            for (TaoBaoShopHistory history : listHistory) {
               TaoBaoShop taoBaoShop = history.getTaoBaoShop();
               if (taoBaoShop != null) {
                  String shopLink = taoBaoShop.getShopLink();
                  if (StringUtil.isNullOrEmpty(shopLink)) {
                     taoBaoShop.setShopLink(TaoBaoUtil.getShopLink(taoBaoShop.getId()));
                  }
                  String shopNameCustom = taoBaoShop.getShopNameCustom();
                  if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
                     taoBaoShop.setShopName(shopNameCustom);
                  }
                  String shopIconCustom = taoBaoShop.getShopIconCustom();
                  if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
                     taoBaoShop.setShopIcon(shopIconCustom);
                  }
                  list.add(taoBaoShop);
               }
            }
         }
         JSONObject data = new JSONObject();
         data.put("count", list.size());
         data.put("count", count);
         data.put("list", JsonUtil.getApiCommonGson().toJson(list));
         out.print(JsonUtil.loadTrueResult(data));
@@ -207,30 +213,54 @@
    * @param out
    */
   @RequestMapping(value = "getShopInfo", method = RequestMethod.POST)
   public void getShopInfo(AcceptData acceptData, Integer page, Long sid, PrintWriter out) {
   public void getShopInfo(AcceptData acceptData, Integer page, Long sid, Long uid, PrintWriter out) {
      try {
         if (sid == null) {
            out.print(JsonUtil.loadFalseResult("缺失店铺id"));
            return;
         }
         JSONObject data = new JSONObject();
         if (page == 1) {
            TaoBaoShop taoBaoShop = taoBaoShopService.selectByPrimaryKey(sid);
            if (taoBaoShop == null) {
               out.print(JsonUtil.loadFalseResult("店铺信息获取失败"));
               return;
            }
            taoBaoShop.setShopLink(TaoBaoUtil.getShopLink(taoBaoShop.getId()));
            data.put("shop", taoBaoShop);
            String shopLink = taoBaoShop.getShopLink();
            if (StringUtil.isNullOrEmpty(shopLink)) {
               taoBaoShop.setShopLink(TaoBaoUtil.getShopLink(taoBaoShop.getId()));
            }
            String shopNameCustom = taoBaoShop.getShopNameCustom();
            if (!StringUtil.isNullOrEmpty(shopNameCustom)) {
               taoBaoShop.setShopName(shopNameCustom);
            }
            String shopIconCustom = taoBaoShop.getShopIconCustom();
            if (!StringUtil.isNullOrEmpty(shopIconCustom)) {
               taoBaoShop.setShopIcon(shopIconCustom);
            }
            data.put("shop", JsonUtil.getApiCommonGson().toJson(taoBaoShop));
            ThreadUtil.run(new Runnable() {
               public void run() {
                  // 添加足迹
                  taoBaoShopHistoryService.addHistory(sid, uid, acceptData.getDevice());
               }
            });
         }
         int pageSize = Constant.PAGE_SIZE;
         List<QualityFactory> listQuery = qualityGoodsService.listByShopId((page - 1) * pageSize, pageSize, sid);
         List<TaoBaoGoodsBrief> listGoods = taoBaoGoodsBriefService.listByShopId((page - 1) * pageSize, pageSize, sid);
         long count = 0;
         JSONArray array = new JSONArray();
         if (listQuery != null && listQuery.size() > 0) {
         if (listGoods != null && listGoods.size() > 0) {
            List<Long> listGid = new ArrayList<Long>();
            for (QualityFactory qualityFactory : listQuery) {
               TaoBaoGoodsBrief taoBaoGoodsBrief = qualityFactory.getTaoBaoGoodsBrief();
               if (taoBaoGoodsBrief == null) {
                  continue;
               }
            for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoods) {
               listGid.add(taoBaoGoodsBrief.getAuctionId());
            }
@@ -250,12 +280,7 @@
                  .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
            BigDecimal proportion = manageService.getFanLiRate();
            for (QualityFactory selectionGoods : listQuery) {
               TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
               if (taoBaoGoodsBrief == null) {
                  continue;
               }
            for (TaoBaoGoodsBrief taoBaoGoodsBrief : listGoods) {
               if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) {
                  boolean stateSale = false; // 默认停售
                  Long goodsId = taoBaoGoodsBrief.getAuctionId();
@@ -273,7 +298,7 @@
               }
               array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
            }
            count = qualityGoodsService.countByShopId(sid);
            count = taoBaoGoodsBriefService.countByShopId(sid);
         }
         data.put("count", count);
         data.put("list", array);