yujian
2019-08-27 d8359ddb48dab5cc797a9d552e11fde571f4920c
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java
@@ -21,6 +21,7 @@
import com.yeshi.fanli.entity.bus.user.UserGoodsStorage;
import com.yeshi.fanli.entity.goods.CommonGoods;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
import com.yeshi.fanli.exception.user.UserGoodsStorageException;
@@ -28,6 +29,7 @@
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
@@ -54,6 +56,51 @@
   @Resource
   private UserGoodsStorageService userGoodsStorageService;
   /**
    *  单个商品加入选品库
    *
    * @param callback
    * @param storageIds
    *            id数组
    * @param out
    */
   @RequestMapping(value = "accordtorage", method = RequestMethod.POST)
   public void accordtorage(AcceptData acceptData, Long uid, long id, Integer goodsType, PrintWriter out) {
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult("用户未登录"));
         return;
      }
      if (goodsType == null) {
         goodsType = Constant.SOURCE_TYPE_TAOBAO;
      }
      try {
         UserGoodsStorage userGoodsStorage = userGoodsStorageService.getByUidAndAuctionId(uid, id, goodsType);
         boolean storageState = false;
         if (userGoodsStorage != null) {
            // 取消加入选品库
            userGoodsStorageService.deleteByPrimaryKey(userGoodsStorage.getId());
         } else {
            // 加入选品库
            Set<Long> set = new HashSet<Long>();
            set.add(id);
            userGoodsStorageService.save(uid, set, goodsType);
            storageState = true;
         }
         JSONObject data = new JSONObject();
         data.put("storageState", storageState);
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("操作失败"));
         e.printStackTrace();
      }
   }
   /**
    * 批量添加选品库
    * 
@@ -203,4 +250,52 @@
      out.print(JsonUtil.loadTrueResult(data));
   }
   /**
    * 分享商品返回二维码图片
    *
    * @param callback
    * @param storageIds
    *            id数组
    * @param out
    */
   @RequestMapping(value = "createShare", method = RequestMethod.POST)
   public void createShare(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) {
      if (StringUtil.isNullOrEmpty(storageIds)) {
         out.print(JsonUtil.loadFalseResult("分享商品不能为空"));
         return;
      }
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult("用户未登录"));
         return;
      }
      try {
         Gson gson = new Gson();
         List<Long> listStorageID = gson.fromJson(storageIds, new TypeToken<ArrayList<Long>>() {}.getType());
         if (listStorageID == null || listStorageID.size() < 9) {
            out.print(JsonUtil.loadFalseResult("分享商品数量不足"));
            return;
         }
         if (listStorageID.size() != 9) {
            out.print(JsonUtil.loadFalseResult("分享商品数量只能是9个"));
            return;
         }
         JSONObject data = userGoodsStorageService.createShareV2(uid, listStorageID);
         out.print(JsonUtil.loadTrueResult(data));
      } catch (UserGoodsStorageException e) {
         out.print(JsonUtil.loadFalseResult("分享失败"));
         e.printStackTrace();
      } catch (UserShareGoodsRecordException e) {
         out.print(JsonUtil.loadFalseResult("分享失败"));
         e.printStackTrace();
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("分享失败"));
         e.printStackTrace();
      }
   }
}