From 5a9e4c13d08d3b1cb7da8f50f1097b33bb113b23 Mon Sep 17 00:00:00 2001 From: 喻健 <喻健@Admin> Date: 星期一, 10 十二月 2018 17:52:03 +0800 Subject: [PATCH] 选品库商品优化 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java | 86 +++++++++++++++++++++++++++++++++++-------- 1 files changed, 70 insertions(+), 16 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 689d9b1..3d9b3fd 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 @@ -4,7 +4,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Set; import javax.annotation.Resource; @@ -15,20 +14,26 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.stereotype.Service; import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.entity.FileUploadResult; import org.yeshi.utils.taobao.TbImgUtil; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.yeshi.fanli.dao.mybatis.user.UserGoodsStorageMapper; +import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum; 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.goods.CommonGoodsException; +import com.yeshi.fanli.exception.share.UserShareGoodsRecordException; 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.goods.CommonGoodsService; 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.MoneyBigDecimalUtil; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.factory.CommonGoodsFactory; @@ -44,6 +49,9 @@ private RedisManager redisManager; @Resource + private ConfigService configService; + + @Resource private CommonGoodsService commonGoodsService; @Resource @@ -51,6 +59,11 @@ @Resource private UserGoodsStorageMapper userGoodsStorageMapper; + + @Resource + private UserShareGoodsRecordService userShareGoodsRecordService; + @Resource + private HongBaoManageService hongBaoManageService; @Override public int deleteByPrimaryKey(Long id) { @@ -194,12 +207,10 @@ long nd = 1000 * 24 * 60 * 60; List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>(); + BigDecimal rate = manageService.getFanLiRate(); Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); - Map<String, String> map = manageService.convertMap(); - BigDecimal rate = manageService.getFanLiRate(); - for (UserGoodsStorage userGoodsStorage : listStorage) { CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); @@ -217,20 +228,28 @@ if (goodsState != null && (goodsState != 1 || !goodsState.equals(1))) { Date updateTime = commonGoods.getUpdateTime(); if (updateTime != null) { - long diff = nowDate.getTime() - updateTime.getTime(); // 璁$畻宸灏戝皬鏃� + long diff = nowDate.getTime() - updateTime.getTime(); + long day = diff / nd; long hour = diff % nd / nh; - if (hour > 1 ) { + if (hour > 1 || day > 0 ) { try { if (commonGoods.getGoodsType() == CommonGoods.GOODS_TYPE_TB) { goodsBrief = redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId()); - goodsBrief.setState(0); + 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(1); + commonGoods.setState(goodsState); + listUpadteCommonGoods.add(commonGoods); e.printStackTrace(); } } @@ -239,25 +258,21 @@ if (goodsBrief == null) { goodsBrief = TaoBaoUtil.convert(commonGoods); - } else { - CommonGoods upadeteCommonGoods = CommonGoodsFactory.create(goodsBrief); - upadeteCommonGoods.setState(goodsState); - listUpadteCommonGoods.add(upadeteCommonGoods); - } + } // 鍒ゆ柇鏄惁宸插垎浜� Integer state = userGoodsStorage.getState(); int shared = UserGoodsStorage.STATE_SHARED; if (state != null && (state == shared || state.equals(shared))) { - if (goodsState != 1 || goodsState.equals(1)) { + if (goodsState != 1 || !goodsState.equals(1)) { goodsBrief.setState(2); // 宸插垎浜姸鎬� } } // 鏀瑰彉鍥剧墖灏哄 - String pictUrl = commonGoods.getPicture(); + String pictUrl = goodsBrief.getPictUrl(); if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) { - commonGoods.setPicture(TbImgUtil.getTBSize320Img(pictUrl)); + goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl)); } String json = gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, rate.toString(), null)); @@ -297,4 +312,43 @@ } return state; } + + @Override + 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, "閫夊搧搴撳晢鍝佷笉瀛樺湪"); + } + + BigDecimal totalMoney = new BigDecimal(0.00); + List<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>(); + + for (UserGoodsStorage userGoodsStorage: listStorage) { + CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); + TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); + listGoodsBrief.add(goodsBrief); + // 宸插垎浜� + userGoodsStorage.setState(1); + userGoodsStorage.setUpdateTime(new Date()); + + String rateStr = hongBaoManageService.get("hongbao_goods_proportion"); + BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(goodsBrief, new BigDecimal(rateStr)); + totalMoney = MoneyBigDecimalUtil.add(totalMoney, money); + } + + String revenue = listGoodsBrief.size() + "涓晢鍝侀浼板垎浜閲戯細楼"+totalMoney; + FileUploadResult loadResult = userShareGoodsRecordService.save(uid, ShareSourceTypeEnum.storage, listGoodsBrief); + + // 鏇存柊涓哄凡鍒嗕韩 + userGoodsStorageMapper.updateBatchSelective(listStorage); + + JSONObject data = new JSONObject(); + data.put("shareImg", loadResult); + data.put("revenue", revenue); + data.put("notifyDesc", configService.get("goods_share_notify")); + + return data; + } } -- Gitblit v1.8.0