From 0cc3b905e5945d1b4b02ee5f91a615bcfd8f08d6 Mon Sep 17 00:00:00 2001
From: yujian <yujian@123.com>
Date: 星期四, 25 七月 2019 11:44:10 +0800
Subject: [PATCH] 京东兼容
---
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java | 228 +++++++++++++++++++++++++++++++++-----------------------
1 files changed, 135 insertions(+), 93 deletions(-)
diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java
index 1eea1d3..adbc194 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java
+++ b/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,22 +56,20 @@
@Resource
private UserGoodsStorageService userGoodsStorageService;
-
/**
* 鎵归噺娣诲姞閫夊搧搴�
*
* @param acceptData
- * @param uid
- * 鐢ㄦ埛id
- * @param ids
- * 绠�鐗堝晢鍝乮d
+ * @param uid 鐢ㄦ埛id
+ * @param ids 绠�鐗堝晢鍝乮d
* @param out
*/
@RequestMapping(value = "addStorage", method = RequestMethod.POST)
public void addStorage(AcceptData acceptData, Long uid, String ids, PrintWriter out) {
try {
Gson gson = new Gson();
- Set<Long> set = gson.fromJson(ids, new TypeToken<HashSet<Long>>() {}.getType());
+ Set<Long> set = gson.fromJson(ids, new TypeToken<HashSet<Long>>() {
+ }.getType());
if (set == null || set.size() == 0) {
out.print(JsonUtil.loadFalseResult("鏈�夋嫨鍟嗗搧"));
return;
@@ -79,11 +79,9 @@
out.print(JsonUtil.loadTrueResult("娣诲姞鎴愬姛"));
} catch (UserGoodsStorageException e) {
out.print(JsonUtil.loadFalseResult(e.getMsg()));
- }
+ }
}
-
-
/**
* 鏌ヨ鐢ㄦ埛閫夊搧搴撴暟鎹�
*
@@ -104,111 +102,155 @@
out.print(JsonUtil.loadFalseResult("骞冲彴绫诲瀷涓嶈兘涓虹┖"));
return;
}
-
+
if (page == null || page < 1) {
page = 1;
}
- try {
- int pageSize = Constant.PAGE_SIZE;
- JSONArray array = new JSONArray();
- JSONObject data = new JSONObject();
-
- if (goodsType == Constant.SOURCE_TYPE_JD) {
- String open = configService.get("share_jd_open");
- if (!"1".equals(open.trim())) {
- data.put("count", 0);
- data.put("result_list", array);
- out.print(JsonUtil.loadTrueResult(data));
- return;
- }
- }
-
- List<UserGoodsStorage> listStorage = userGoodsStorageService.listQueryByUid((page - 1) * pageSize, pageSize,
- uid, goodsType);
- if (listStorage == null || listStorage.size() == 0) {
+ int pageSize = Constant.PAGE_SIZE;
+ JSONArray array = new JSONArray();
+ JSONObject data = new JSONObject();
+
+ if (goodsType == Constant.SOURCE_TYPE_JD) {
+ String open = configService.get("share_jd_open");
+ if (!"1".equals(open.trim())) {
data.put("count", 0);
data.put("result_list", array);
out.print(JsonUtil.loadTrueResult(data));
return;
}
+ }
- // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭
- List<TaoBaoGoodsBrief> listTaoKeGoods = null;
- if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
- List<Long> listGid = new ArrayList<Long>();
- for (UserGoodsStorage userGoodsStorage : listStorage) {
- CommonGoods commonGoods = userGoodsStorage.getCommonGoods();
- if (commonGoods == null) {
- continue;
- }
- listGid.add(commonGoods.getGoodsId());
- }
+ List<UserGoodsStorage> listStorage = userGoodsStorageService.listQueryByUid((page - 1) * pageSize, pageSize,
+ uid, goodsType);
+ if (listStorage == null || listStorage.size() == 0) {
+ data.put("count", 0);
+ data.put("result_list", array);
+ out.print(JsonUtil.loadTrueResult(data));
+ return;
+ }
- try {
- listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
- } catch (TaoKeApiException e) {
- e.printStackTrace();
- } catch (TaobaoGoodsDownException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
- .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
-
- BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
- BigDecimal shareRate = hongBaoManageService.getShareRate();
-
+ // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭
+ List<TaoBaoGoodsBrief> listTaoKeGoods = null;
+ if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
+ List<Long> listGid = new ArrayList<Long>();
for (UserGoodsStorage userGoodsStorage : listStorage) {
CommonGoods commonGoods = userGoodsStorage.getCommonGoods();
if (commonGoods == null) {
continue;
}
-
- // 娣樺疂鍟嗗搧楠岃瘉鍦ㄥ敭
- if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
- if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) {
- int state = 1; // 榛樿鍋滃敭
- Long goodsId = commonGoods.getGoodsId();
- for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
- Long auctionId = taoKeGoods.getAuctionId();
- if (goodsId == auctionId || goodsId.equals(auctionId)) {
- state = 0; // 鍦ㄥ敭
- break;
- }
- }
- commonGoods.setState(state);
- }
- }
-
- // 鍒ゆ柇鏄惁宸插垎浜紝 宸插垎浜樉绀哄凡涓嬫灦
- Integer storageState = userGoodsStorage.getState();
- if (storageState != null && storageState == UserGoodsStorage.STATE_SHARED) {
- Integer goodsState = commonGoods.getState();
- if (goodsState != null && goodsState != 1) {
- commonGoods.setState(2);
- }
- }
-
- GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate, shareRate);
-
- JSONObject dataObject = new JSONObject();
- dataObject.put("storageId", userGoodsStorage.getId());
- dataObject.put("goods", gson.toJson(detailVO));
- array.add(dataObject);
+ listGid.add(commonGoods.getGoodsId());
}
- long count = userGoodsStorageService.countQueryByUid(uid, goodsType);
- data.put("count", count);
- data.put("result_list", array);
+ try {
+ listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
+ } catch (TaoKeApiException e) {
+ e.printStackTrace();
+ } catch (TaobaoGoodsDownException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
+ .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
+
+ BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
+ BigDecimal shareRate = hongBaoManageService.getShareRate();
+
+ for (UserGoodsStorage userGoodsStorage : listStorage) {
+ CommonGoods commonGoods = userGoodsStorage.getCommonGoods();
+ if (commonGoods == null) {
+ continue;
+ }
+
+ // 娣樺疂鍟嗗搧楠岃瘉鍦ㄥ敭
+ if (goodsType == Constant.SOURCE_TYPE_TAOBAO) {
+ if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) {
+ int state = 1; // 榛樿鍋滃敭
+ Long goodsId = commonGoods.getGoodsId();
+ for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
+ Long auctionId = taoKeGoods.getAuctionId();
+ if (goodsId == auctionId || goodsId.equals(auctionId)) {
+ state = 0; // 鍦ㄥ敭
+ break;
+ }
+ }
+ commonGoods.setState(state);
+ }
+ }
+
+ // 鍒ゆ柇鏄惁宸插垎浜紝 宸插垎浜樉绀哄凡涓嬫灦
+ Integer storageState = userGoodsStorage.getState();
+ if (storageState != null && storageState == UserGoodsStorage.STATE_SHARED) {
+ Integer goodsState = commonGoods.getState();
+ if (goodsState != null && goodsState != 1) {
+ commonGoods.setState(2);
+ }
+ }
+
+ GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate, shareRate);
+ detailVO.setId(commonGoods.getId());
+
+ JSONObject dataObject = new JSONObject();
+ dataObject.put("storageId", userGoodsStorage.getId());
+ dataObject.put("goods", gson.toJson(detailVO));
+ array.add(dataObject);
+ }
+
+ long count = userGoodsStorageService.countQueryByUid(uid, goodsType);
+ data.put("count", count);
+ data.put("result_list", array);
+ 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("鍔犺浇鍒楄〃澶辫触"));
+ out.print(JsonUtil.loadFalseResult("鍒嗕韩澶辫触"));
e.printStackTrace();
}
}
-
}
--
Gitblit v1.8.0