From bf0a347104579e5f7a2ed6e660ebb9f17f76ffc0 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期五, 17 一月 2020 16:51:54 +0800
Subject: [PATCH] 后台编辑
---
fanli/src/main/java/com/yeshi/fanli/controller/client/v2/ShareStorageControllerV2.java | 289 ++++++++++++++++++++++++++++++++++++++-------------------
1 files changed, 193 insertions(+), 96 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 2e0536c..9ede25a 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
@@ -1,7 +1,6 @@
package com.yeshi.fanli.controller.client.v2;
import java.io.PrintWriter;
-import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -17,17 +16,22 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.dto.ConfigParamsDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.UserGoodsStorage;
import com.yeshi.fanli.entity.goods.CommonGoods;
+import com.yeshi.fanli.entity.system.ConfigKeyEnum;
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;
import com.yeshi.fanli.service.inter.config.ConfigService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
+import com.yeshi.fanli.service.inter.order.config.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.VersionUtil;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
@@ -54,7 +58,49 @@
@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();
+ }
+ }
+
/**
* 鎵归噺娣诲姞閫夊搧搴�
*
@@ -69,7 +115,8 @@
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,17 +126,17 @@
out.print(JsonUtil.loadTrueResult("娣诲姞鎴愬姛"));
} catch (UserGoodsStorageException e) {
out.print(JsonUtil.loadFalseResult(e.getMsg()));
- }
+ }
}
-
-
/**
* 鏌ヨ鐢ㄦ埛閫夊搧搴撴暟鎹�
*
* @param acceptData
- * @param page 椤电爜 鍒濆鍊� 1
- * @param uid 鐢ㄦ埛id
+ * @param page
+ * 椤电爜 鍒濆鍊� 1
+ * @param uid
+ * 鐢ㄦ埛id
* @param out
*/
@RequestMapping(value = "getlist", method = RequestMethod.POST)
@@ -104,113 +151,163 @@
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(ConfigKeyEnum.shareOpenJD.getKey());
+ 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);
- detailVO.setId(commonGoods.getId());
-
-
- 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);
- out.print(JsonUtil.loadTrueResult(data));
+ 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();
+
+ ConfigParamsDTO paramsDTO = hongBaoManageService.getShowComputeRate(acceptData.getPlatform(),
+ acceptData.getVersion());
+
+ 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, paramsDTO);
+ 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 (!VersionUtil.greaterThan_2_0_5(acceptData.getPlatform(), acceptData.getVersion())) {
+
+ 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, true);
+ out.print(JsonUtil.loadTrueResult(data));
+ } else {
+ JSONObject data = userGoodsStorageService.createShareV2(uid, listStorageID, false);
+ 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