From d28bed1a1275131a5ca37f7da37961e2b518ac07 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期一, 26 八月 2019 13:44:00 +0800 Subject: [PATCH] 淘礼金创建异常处理 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java | 76 ++++++++++++++++++++++++++++++------- 1 files changed, 61 insertions(+), 15 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 d65ff4f..c7056a0 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 @@ -10,6 +10,7 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.yeshi.utils.JsonUtil; import org.yeshi.utils.entity.FileUploadResult; @@ -32,6 +33,7 @@ import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.user.UserGoodsStorageService; import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; +import com.yeshi.fanli.util.CommonGoodsUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.MoneyBigDecimalUtil; import com.yeshi.fanli.util.RedisManager; @@ -160,15 +162,15 @@ jdGoods = JDApiUtil.getGoodsDetail(auctionId); } if (jdGoods == null) { - throw new UserGoodsStorageException(1, "auctionId鍟嗗搧宸蹭笅鏋�"); + throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); } commonGoods = CommonGoodsFactory.create(jdGoods); - } else if (goodsType == Constant.SOURCE_TYPE_JD) { + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { // 鎷煎澶� PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(auctionId); if (pddGoods == null) { - throw new UserGoodsStorageException(1, "auctionId鍟嗗搧宸蹭笅鏋�"); + throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); } commonGoods = CommonGoodsFactory.create(pddGoods); } else { @@ -178,7 +180,7 @@ TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(auctionId); commonGoods = CommonGoodsFactory.create(goodsBrief); } catch (TaobaoGoodsDownException e) { - throw new UserGoodsStorageException(1, "auctionId鍟嗗搧宸蹭笅鏋�"); + throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); } } @@ -215,6 +217,7 @@ @Override + @Transactional public void addCommonGoods(Long uid, Set<Long> ids) throws UserGoodsStorageException { if (uid == null) { @@ -348,15 +351,14 @@ } return state; } - + @Override - public JSONObject shareGoods(Long uid, List<Long> listStorageID, Integer goodsType) + public JSONObject shareGoods(Long uid, List<Long> listStorageID) throws UserGoodsStorageException, UserShareGoodsRecordException { List<UserGoodsStorage> listStorage = userGoodsStorageMapper.listQueryByIds(listStorageID); if (listStorage == null || listStorage.size() == 0) { throw new UserGoodsStorageException(1, "閫夊搧搴撳晢鍝佷笉瀛樺湪"); } - List<UserGoodsStorage> listResult = new ArrayList<UserGoodsStorage>(); // 杩樺師椤哄簭 鐢ㄤ簬鍒跺浘 @@ -391,22 +393,66 @@ data.put("revenue", listGoodsBrief.size() + "涓晢鍝侀浼板垎浜閲戯細楼"+totalMoney); data.put("shareId", shareRecord.getRedisKey()); data.put("shareImg", uploadResult); - - if (goodsType == null) { - goodsType = Constant.SOURCE_TYPE_TAOBAO; + data.put("notifyDesc", configService.get("goods_share_multiple_notify")); + return data; + } + + + + @Override + public JSONObject createShareV2(Long uid, List<Long> listStorageID) throws UserGoodsStorageException, UserShareGoodsRecordException { + List<UserGoodsStorage> listStorage = userGoodsStorageMapper.listQueryByIds(listStorageID); + if (listStorage == null || listStorage.size() == 0) { + throw new UserGoodsStorageException(1, "閫夊搧搴撳晢鍝佷笉瀛樺湪"); } + + List<UserGoodsStorage> listResult = new ArrayList<UserGoodsStorage>(); + // 杩樺師椤哄簭 鐢ㄤ簬鍒跺浘 + for (Long sid: listStorageID) { + for (UserGoodsStorage torage: listStorage) { + Long id = torage.getId(); + if (sid == id || sid.equals(id)) { + listResult.add(torage); + break; + } + } + } + + BigDecimal totalMoney = new BigDecimal(0.00); + List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>(); + + Integer goodsType = null; + BigDecimal rate = hongBaoManageService.getShareRate(); + for (UserGoodsStorage userGoodsStorage: listResult) { + CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); + BigDecimal money = CommonGoodsUtil.getCommission(commonGoods, rate); + totalMoney = MoneyBigDecimalUtil.add(totalMoney, money); + listCommonGoods.add(commonGoods); + + if (goodsType == null) { + goodsType = commonGoods.getGoodsType(); + } + } + + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsStorageV2(uid, listCommonGoods, listStorageID); + FileUploadResult uploadResult = new FileUploadResult(); + uploadResult.setUrl(shareRecord.getSharePictureUrl()); + + JSONObject data = new JSONObject(); + data.put("revenue", listCommonGoods.size() + "涓晢鍝侀浼板垎浜閲戯細楼"+totalMoney); + data.put("shareId", shareRecord.getRedisKey()); + data.put("shareImg", uploadResult); // 鎻愮ず璇笉鍚� if (goodsType == Constant.SOURCE_TYPE_JD) { - // 浜笢 TODO - data.put("notifyDesc", configService.get("goods_share_multiple_notify")); + // 浜笢 + data.put("notifyDesc", configService.get("goods_share_notify_jd")); } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - // 鎷煎澶� TODO - data.put("notifyDesc", configService.get("goods_share_multiple_notify")); + // 鎷煎澶� + data.put("notifyDesc", configService.get("goods_share_notify_pdd")); } else { data.put("notifyDesc", configService.get("goods_share_multiple_notify")); } - return data; } -- Gitblit v1.8.0