From 7dd830c1d6247a8360e6fba6ee8a286b57f0e8b1 Mon Sep 17 00:00:00 2001 From: 喻健 <喻健@Admin> Date: 星期三, 19 十二月 2018 16:50:49 +0800 Subject: [PATCH] 验证商品是否在售:收藏、选品库、分享记录 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java | 115 +++++++++++++++++++++------------------------------------ 1 files changed, 42 insertions(+), 73 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java index 2d3f951..ed90bcd 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java @@ -15,7 +15,6 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import org.yeshi.utils.JsonUtil; -import org.yeshi.utils.taobao.TbImgUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -26,6 +25,7 @@ import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.goods.CommonGoodsException; 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; @@ -35,9 +35,9 @@ import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.RedisManager; -import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.factory.CommonGoodsFactory; import com.yeshi.fanli.util.taobao.TaoBaoUtil; +import com.yeshi.fanli.util.taobao.TaoKeApiUtil; @Service public class UserGoodsStorageServiceImpl implements UserGoodsStorageService { @@ -207,15 +207,31 @@ return array; } - Date nowDate = new Date(); - long nh = 1000 * 60 * 60; - long nd = 1000 * 24 * 60 * 60; - List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>(); + + List<Long> listGid = new ArrayList<Long>(); + for (UserGoodsStorage userGoodsStorage : listStorage) { + CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); + if (commonGoods == null) { + continue; + } + listGid.add(commonGoods.getGoodsId()); + } + + // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭 + List<TaoBaoGoodsBrief> listTaoKeGoods = null; + try { + listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); + } catch (TaoKeApiException e) { + e.printStackTrace(); + } catch (TaobaoGoodsDownException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } BigDecimal rate = manageService.getFanLiRate(); Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); - for (UserGoodsStorage userGoodsStorage : listStorage) { CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); @@ -223,83 +239,36 @@ continue; } - TaoBaoGoodsBrief goodsBrief = null; - JSONObject dataObject = new JSONObject(); - - - // 鏇存柊涓�涓皬鏃朵箣鍐呯殑鍟嗗搧涓嶅啀鏇存柊 - Integer goodsState = commonGoods.getState(); - // 鐘舵�佹湭涓嬫灦鏃惰繘琛屾洿鏂� - if (goodsState != null && (goodsState != 1 || !goodsState.equals(1))) { - Date updateTime = commonGoods.getUpdateTime(); - if (updateTime != null) { - // 璁$畻宸灏戝皬鏃� - long diff = nowDate.getTime() - updateTime.getTime(); - long day = diff / nd; - long hour = diff % nd / nh; - if (hour > 1 || day > 0 ) { - try { - if (commonGoods.getGoodsType() == CommonGoods.GOODS_TYPE_TB) { - goodsBrief = redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId()); - - goodsState = 0; - goodsBrief.setState(goodsState); - - CommonGoods upadeteCommonGoods = CommonGoodsFactory.create(goodsBrief); - upadeteCommonGoods.setState(goodsState); - upadeteCommonGoods.setId(commonGoods.getId()); - listUpadteCommonGoods.add(upadeteCommonGoods); - } - } catch (TaobaoGoodsDownException e) { - // 宸蹭笅鏋� - goodsState = 1; - commonGoods.setState(goodsState); - listUpadteCommonGoods.add(commonGoods); - e.printStackTrace(); - } - } + 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); } - if (goodsBrief == null) { - goodsBrief = TaoBaoUtil.convert(commonGoods); - } + TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); // 鍒ゆ柇鏄惁宸插垎浜� - Integer state = userGoodsStorage.getState(); - int shared = UserGoodsStorage.STATE_SHARED; - if (state != null && (state == shared || state.equals(shared))) { - if (goodsState != 1 || !goodsState.equals(1)) { - goodsBrief.setState(2); // 宸插垎浜姸鎬� + Integer storageState = userGoodsStorage.getState(); + if (storageState != null && storageState == UserGoodsStorage.STATE_SHARED) { + Integer goodsState = goodsBrief.getState(); + if (goodsState != null && goodsState != 1) { + goodsBrief.setState(2); // 宸插垎浜姸鎬� 浼樺厛鏄剧ず宸蹭笅鏋� } } - - // 鏀瑰彉鍥剧墖灏哄 - String pictUrl = goodsBrief.getPictUrl(); - if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) { - goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl)); - } + String json = gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, rate.toString(), null)); - + + JSONObject dataObject = new JSONObject(); dataObject.put("storageId", userGoodsStorage.getId()); dataObject.put("goods", json); array.add(dataObject); - } - - - if (listUpadteCommonGoods.size() > 0) { - executor.execute(new Runnable() { - @Override - public void run() { - try { - // 鏇存柊绠�鐗堜俊鎭� - commonGoodsService.updateBatchCommonGoods(listUpadteCommonGoods); - } catch (Exception e) { - e.printStackTrace(); - } - - } - }); } return array; -- Gitblit v1.8.0