yujian
2019-03-01 9dedfa92c34c92d42230e151766726a8e4a7806f
fanli/src/main/java/com/yeshi/fanli/controller/client/UserGoodsStorageController.java
@@ -20,7 +20,9 @@
import com.google.gson.reflect.TypeToken;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserGoodsStorage;
import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
import com.yeshi.fanli.exception.user.UserGoodsStorageException;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.StringUtil;
@@ -30,10 +32,59 @@
public class UserGoodsStorageController {
   @Resource
   private ConfigService configService;
   @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 auctionId, PrintWriter out) {
      if (auctionId == null) {
         out.print(JsonUtil.loadFalseResult("未选择商品"));
         return;
      }
      if (uid == null) {
         out.print(JsonUtil.loadFalseResult("用户未登录"));
         return;
      }
      try {
         UserGoodsStorage userGoodsStorage = userGoodsStorageService.getByUidAndAuctionId(uid, auctionId);
         boolean storageState = false;
         if (userGoodsStorage != null) {
            // 取消加入选品库
            userGoodsStorageService.deleteByPrimaryKey(userGoodsStorage.getId());
         } else {
            // 加入选品库
            Set<Long> set = new HashSet<Long>();
            set.add(auctionId);
            userGoodsStorageService.save(uid, set);
            storageState = true;
         }
         JSONObject data = new JSONObject();
         data.put("storageState", storageState);
         out.print(JsonUtil.loadTrueResult(data));
      } catch (Exception e) {
         out.print(JsonUtil.loadFalseResult("操作失败"));
         e.printStackTrace();
      }
   }
   /**
    * 批量添加选品库
    * 
    * @param acceptData
    * @param uid
@@ -88,7 +139,7 @@
         int pageSize = Constant.PAGE_SIZE;
         JSONObject data = new JSONObject();
         JSONArray array = null;
         JSONArray array = new JSONArray();
         long count = userGoodsStorageService.countQueryByUid(uid);
         if (count > 0) {
@@ -144,19 +195,21 @@
   }
   
   
   /**
    * 根据商品id移除选品库
    * 分享商品返回二维码图片
    * 
    * @param callback
    * @param storageIds
    *            id数组
    * @param out
    */
   @RequestMapping(value = "accordtorage", method = RequestMethod.POST)
   public void accordtorage(AcceptData acceptData, Long uid, Long auctionId, PrintWriter out) {
   @RequestMapping(value = "sharegoods", method = RequestMethod.POST)
   public void shareGoods(AcceptData acceptData, Long uid, String storageIds, PrintWriter out) {
      if (auctionId == null) {
         out.print(JsonUtil.loadFalseResult("未选择商品"));
      if (StringUtil.isNullOrEmpty(storageIds)) {
         out.print(JsonUtil.loadFalseResult("分享商品不能为空"));
         return;
      }
      
@@ -166,29 +219,33 @@
      }
      try {
         UserGoodsStorage userGoodsStorage = userGoodsStorageService.getByUidAndAuctionId(uid, auctionId);
         boolean storageState = false;
         if (userGoodsStorage != null) {
            // 取消加入选品库
            userGoodsStorageService.deleteByPrimaryKey(userGoodsStorage.getId());
         } else {
            // 加入选品库
            Set<Long> set = new HashSet<Long>();
            set.add(auctionId);
            userGoodsStorageService.save(uid, set);
            storageState = true;
         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;
         }
         
         JSONObject data = new JSONObject();
         data.put("storageState", storageState);
         out.print(JsonUtil.loadTrueResult(data));
         if (listStorageID.size() != 9) {
            out.print(JsonUtil.loadFalseResult("分享商品数量只能是9个"));
            return;
         }
         JSONObject data = userGoodsStorageService.shareGoods(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("操作失败"));
         out.print(JsonUtil.loadFalseResult("分享失败"));
         e.printStackTrace();
      }
   }
}