From 81da61b828e29b7745e1382dfbbaeb685dc083ef Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 23 一月 2024 17:17:55 +0800 Subject: [PATCH] 抖音转链修改 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserGoodsStorageServiceImpl.java | 940 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 470 insertions(+), 470 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 eda1a22..23fe2b3 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 @@ -1,470 +1,470 @@ -package com.yeshi.fanli.service.impl.user; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Set; - -import javax.annotation.Resource; - -import com.yeshi.fanli.entity.SystemEnum; -import com.yeshi.fanli.entity.bus.user.UserInfo; -import com.yeshi.fanli.service.inter.user.UserInfoService; -import com.yeshi.fanli.util.*; -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.MoneyBigDecimalUtil; -import org.yeshi.utils.entity.FileUploadResult; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.yeshi.fanli.dao.mybatis.user.UserGoodsStorageMapper; -import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; -import com.yeshi.fanli.dto.share.ShareGoodsRecordDTO; -import com.yeshi.fanli.entity.bus.user.UserGoodsStorage; -import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum; -import com.yeshi.fanli.entity.goods.CommonGoods; -import com.yeshi.fanli.entity.jd.JDGoods; -import com.yeshi.fanli.entity.system.ConfigKeyEnum; -import com.yeshi.goods.facade.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; -import com.yeshi.fanli.service.inter.goods.CommonGoodsService; -import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; -import com.yeshi.fanli.service.inter.user.UserGoodsStorageService; -import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; -import com.yeshi.fanli.util.factory.CommonGoodsFactory; -import com.yeshi.fanli.util.jd.JDApiUtil; -import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; -import com.yeshi.fanli.util.taobao.TaoBaoUtil; -import com.yeshi.fanli.util.taobao.TaoKeApiUtil; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -@Service -public class UserGoodsStorageServiceImpl implements UserGoodsStorageService { - - @Resource(name = "taskExecutor") - private TaskExecutor executor; - - @Resource - private RedisManager redisManager; - - @Resource - private ConfigService configService; - - @Resource - private CommonGoodsService commonGoodsService; - - @Resource - private HongBaoManageService manageService; - - @Resource - private UserGoodsStorageMapper userGoodsStorageMapper; - - @Resource - private UserShareGoodsRecordService userShareGoodsRecordService; - @Resource - private HongBaoManageService hongBaoManageService; - - @Resource - private UserInfoService userInfoService; - - @Override - public int deleteByPrimaryKey(Long id) { - return userGoodsStorageMapper.deleteByPrimaryKey(id); - } - - @Override - public int insert(UserGoodsStorage record) { - return userGoodsStorageMapper.insert(record); - } - - @Override - public int insertSelective(UserGoodsStorage record) { - return userGoodsStorageMapper.insertSelective(record); - } - - @Override - public UserGoodsStorage selectByPrimaryKey(Long id) { - return userGoodsStorageMapper.selectByPrimaryKey(id); - } - - @Override - public int updateByPrimaryKeySelective(UserGoodsStorage record) { - return userGoodsStorageMapper.updateByPrimaryKeySelective(record); - } - - @Override - public int updateByPrimaryKey(UserGoodsStorage record) { - return userGoodsStorageMapper.updateByPrimaryKey(record); - } - - /** - * 鏍规嵁涓婚敭鎵归噺鍒犻櫎 - * - * @param list - * @return - */ - @Override - public int deleteBatchByPrimaryKey(List<Long> list) { - return userGoodsStorageMapper.deleteBatchByPrimaryKey(list); - } - - /** - * 鏍规嵁涓婚敭 銆乽id 鎵归噺鍒犻櫎 - * - * @param list - * @return - */ - @Override - public int deleteBatchByUidAndPrimaryKey(Long uid, List<Long> list) { - return userGoodsStorageMapper.deleteBatchByUidAndPrimaryKey(uid, list); - } - - @Override - public List<UserGoodsStorage> listQueryByUid(long start, int count, Long uid, Integer source) { - return userGoodsStorageMapper.listQueryByUid(start, count, uid, source); - } - - @Override - public UserGoodsStorage getByUidAndAuctionId(Long uid, Long auctionId, Integer goodsType) { - return userGoodsStorageMapper.getByUidAndAuctionId(uid, auctionId, goodsType); - } - - @Override - public long countQueryByUid(Long uid, Integer source) { - return userGoodsStorageMapper.countQueryByUid(uid, source); - } - - @Override - public void save(Long uid, Set<Long> auctionIds, Integer goodsType) throws UserGoodsStorageException { - - if (uid == null) { - throw new UserGoodsStorageException(1, "鐢ㄦ埛灏氭湭鐧诲綍"); - } - - if (auctionIds == null || auctionIds.size() == 0) { - throw new UserGoodsStorageException(1, "鍟嗗搧ID涓虹┖"); - } - - for (Long auctionId : auctionIds) { - CommonGoods commonGoods = null; - if (goodsType == null) { - goodsType = Constant.SOURCE_TYPE_TAOBAO; - } - - if (goodsType == Constant.SOURCE_TYPE_JD) { - // 浜笢 - JDGoods jdGoods = JDApiUtil.queryGoodsDetail(auctionId); - if (jdGoods == null) { - jdGoods = JDApiUtil.getGoodsDetail(auctionId); - } - if (jdGoods == null) { - throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); - } - commonGoods = CommonGoodsFactory.create(jdGoods); - - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - // 鎷煎澶� - PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(auctionId); - if (pddGoods == null) { - throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); - } - commonGoods = CommonGoodsFactory.create(pddGoods); - } else { - // 娣樺疂 - try { - // 鑾峰彇鍟嗗搧璇︽儏 - TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(auctionId); - commonGoods = CommonGoodsFactory.create(goodsBrief); - } catch (TaobaoGoodsDownException e) { - throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); - } - } - - if (commonGoods != null) { - try { - commonGoodsService.addOrUpdateCommonGoods(commonGoods); - } catch (CommonGoodsException e) { - e.printStackTrace(); - throw new UserGoodsStorageException(1, "鍟嗗搧淇℃伅鏇存柊澶辫触"); - } - - Long cid = commonGoods.getId(); - - UserGoodsStorage goodsStorage = userGoodsStorageMapper.getByUidAndCid(uid, cid); - - if (goodsStorage != null) { - // 鍒濆璇濈姸鎬� - goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); - goodsStorage.setUpdateTime(new Date()); - userGoodsStorageMapper.updateByPrimaryKeySelective(goodsStorage); - } else { - goodsStorage = new UserGoodsStorage(); - goodsStorage.setUid(uid); - ; - goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); - goodsStorage.setCommonGoods(commonGoods); - goodsStorage.setCreateTime(new Date()); - goodsStorage.setUpdateTime(new Date()); - userGoodsStorageMapper.insertSelective(goodsStorage); - } - } - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void addCommonGoods(Long uid, Set<Long> ids) throws UserGoodsStorageException { - - if (uid == null) { - throw new UserGoodsStorageException(1, "鐢ㄦ埛灏氭湭鐧诲綍"); - } - - if (ids == null || ids.size() == 0) { - throw new UserGoodsStorageException(1, "鍟嗗搧ID涓虹┖"); - } - - for (Long id : ids) { - CommonGoods commonGoods = commonGoodsService.selectByPrimaryKey(id); - if (commonGoods != null) { - UserGoodsStorage goodsStorage = userGoodsStorageMapper.getByUidAndCid(uid, id); - - if (goodsStorage != null) { - // 鍒濆璇濈姸鎬� - goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); - goodsStorage.setUpdateTime(new Date()); - userGoodsStorageMapper.updateByPrimaryKeySelective(goodsStorage); - } else { - goodsStorage = new UserGoodsStorage(); - goodsStorage.setUid(uid); - ; - goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); - goodsStorage.setCommonGoods(commonGoods); - goodsStorage.setCreateTime(new Date()); - goodsStorage.setUpdateTime(new Date()); - userGoodsStorageMapper.insertSelective(goodsStorage); - } - } - } - } - - @Override - public JSONArray getMyStorage(int page, int pageSize, Long uid, Integer source) throws UserGoodsStorageException { - - JSONArray array = new JSONArray(); - - List<UserGoodsStorage> listStorage = listQueryByUid(page, pageSize, uid, source); - if (listStorage == null || listStorage.size() == 0) { - return array; - } - - if (source == null) { - source = Constant.SOURCE_TYPE_TAOBAO; - } - - List<TaoBaoGoodsBrief> listTaoKeGoods = null; - if (source == 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()); - } - - // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭 - try { - listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); - } catch (TaoKeApiException e) { - e.printStackTrace(); - } catch (TaobaoGoodsDownException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - SystemEnum system = userInfoService.getUserSystem(uid); - BigDecimal rate = manageService.getFanLiRate(UserLevelEnum.daRen, system); - Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) - .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); - - for (UserGoodsStorage userGoodsStorage : listStorage) { - CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); - if (commonGoods == null) { - continue; - } - - int state = 0; - Integer goodsType = commonGoods.getGoodsType(); - - if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 && goodsType != null - && goodsType == Constant.SOURCE_TYPE_TAOBAO) { - 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); - TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); - - // 鍒ゆ柇鏄惁宸插垎浜� - Integer storageState = userGoodsStorage.getState(); - if (storageState != null && storageState == UserGoodsStorage.STATE_SHARED) { - Integer goodsState = goodsBrief.getState(); - if (goodsState != null && goodsState != 1) { - goodsBrief.setState(2); // 宸插垎浜姸鎬� 浼樺厛鏄剧ず宸蹭笅鏋� - } - } - - 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); - } - - return array; - } - - @Override - public boolean isExistStorage(Long uid, Long auctionId, Integer goodType) { - boolean state = false; - if (uid != null && auctionId != null) { - UserGoodsStorage userGoodsStorage = userGoodsStorageMapper.getByUidAndAuctionId(uid, auctionId, goodType); - if (userGoodsStorage != null) { - state = true; - } - } - 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, "閫夊搧搴撳晢鍝佷笉瀛樺湪"); - } - - 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<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>(); - - SystemEnum system = userInfoService.getUserSystem(uid); - - BigDecimal rate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,system); - for (UserGoodsStorage userGoodsStorage : listResult) { - CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); - TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); - listGoodsBrief.add(goodsBrief); - - BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(goodsBrief, rate, true); - totalMoney = MoneyBigDecimalUtil.add(totalMoney, money); - } - - ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsStorage(uid, listGoodsBrief, - listStorageID); - FileUploadResult uploadResult = new FileUploadResult(); - uploadResult.setUrl(shareRecord.getSharePictureUrl()); - - UserInfo user = userInfoService.selectByPKey(uid); - - JSONObject data = new JSONObject(); - data.put("revenue", listGoodsBrief.size() + "涓晢鍝侀浼板垎浜閲戯細楼" + totalMoney); - data.put("shareId", shareRecord.getRedisKey()); - data.put("shareImg", uploadResult); - data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareMultipleNotify.getKey(), user.getSystem())); - return data; - } - - @Override - public JSONObject createShareV2(Long uid, List<Long> listStorageID, boolean needDrawPicture) - 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; - } - } - } - - SystemEnum system = userInfoService.getUserSystem(uid); - - BigDecimal totalMoney = new BigDecimal(0.00); - List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>(); - - Integer goodsType = null; - BigDecimal rate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,system); - 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, needDrawPicture); - 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) { - // 浜笢 - data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotifyJD.getKey(), system)); - } else if (goodsType == Constant.SOURCE_TYPE_PDD) { - // 鎷煎澶� - data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotifyPDD.getKey(), system)); - } else { - data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareMultipleNotify.getKey(), system)); - } - return data; - } - -} +package com.yeshi.fanli.service.impl.user; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.entity.bus.user.UserInfo; +import com.yeshi.fanli.service.inter.user.UserInfoService; +import com.yeshi.fanli.util.*; +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.MoneyBigDecimalUtil; +import org.yeshi.utils.entity.FileUploadResult; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.yeshi.fanli.dao.mybatis.user.UserGoodsStorageMapper; +import com.yeshi.fanli.dto.pdd.PDDGoodsDetail; +import com.yeshi.fanli.dto.share.ShareGoodsRecordDTO; +import com.yeshi.fanli.entity.bus.user.UserGoodsStorage; +import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum; +import com.yeshi.fanli.entity.goods.CommonGoods; +import com.yeshi.fanli.entity.jd.JDGoods; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; +import com.yeshi.goods.facade.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; +import com.yeshi.fanli.service.inter.goods.CommonGoodsService; +import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; +import com.yeshi.fanli.service.inter.user.UserGoodsStorageService; +import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService; +import com.yeshi.fanli.util.factory.CommonGoodsFactory; +import com.yeshi.fanli.util.jd.JDApiUtil; +import com.yeshi.fanli.util.pinduoduo.PinDuoDuoApiUtil; +import com.yeshi.fanli.util.taobao.TaoBaoUtil; +import com.yeshi.fanli.util.taobao.TaoKeApiUtil; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +@Service +public class UserGoodsStorageServiceImpl implements UserGoodsStorageService { + + @Resource(name = "taskExecutor") + private TaskExecutor executor; + + @Resource + private RedisManager redisManager; + + @Resource + private ConfigService configService; + + @Resource + private CommonGoodsService commonGoodsService; + + @Resource + private HongBaoManageService manageService; + + @Resource + private UserGoodsStorageMapper userGoodsStorageMapper; + + @Resource + private UserShareGoodsRecordService userShareGoodsRecordService; + @Resource + private HongBaoManageService hongBaoManageService; + + @Resource + private UserInfoService userInfoService; + + @Override + public int deleteByPrimaryKey(Long id) { + return userGoodsStorageMapper.deleteByPrimaryKey(id); + } + + @Override + public int insert(UserGoodsStorage record) { + return userGoodsStorageMapper.insert(record); + } + + @Override + public int insertSelective(UserGoodsStorage record) { + return userGoodsStorageMapper.insertSelective(record); + } + + @Override + public UserGoodsStorage selectByPrimaryKey(Long id) { + return userGoodsStorageMapper.selectByPrimaryKey(id); + } + + @Override + public int updateByPrimaryKeySelective(UserGoodsStorage record) { + return userGoodsStorageMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(UserGoodsStorage record) { + return userGoodsStorageMapper.updateByPrimaryKey(record); + } + + /** + * 鏍规嵁涓婚敭鎵归噺鍒犻櫎 + * + * @param list + * @return + */ + @Override + public int deleteBatchByPrimaryKey(List<Long> list) { + return userGoodsStorageMapper.deleteBatchByPrimaryKey(list); + } + + /** + * 鏍规嵁涓婚敭 銆乽id 鎵归噺鍒犻櫎 + * + * @param list + * @return + */ + @Override + public int deleteBatchByUidAndPrimaryKey(Long uid, List<Long> list) { + return userGoodsStorageMapper.deleteBatchByUidAndPrimaryKey(uid, list); + } + + @Override + public List<UserGoodsStorage> listQueryByUid(long start, int count, Long uid, Integer source) { + return userGoodsStorageMapper.listQueryByUid(start, count, uid, source); + } + + @Override + public UserGoodsStorage getByUidAndAuctionId(Long uid, String auctionId, Integer goodsType) { + return userGoodsStorageMapper.getByUidAndAuctionId(uid, auctionId, goodsType); + } + + @Override + public long countQueryByUid(Long uid, Integer source) { + return userGoodsStorageMapper.countQueryByUid(uid, source); + } + + @Override + public void save(Long uid, Set<String> auctionIds, Integer goodsType) throws UserGoodsStorageException { + + if (uid == null) { + throw new UserGoodsStorageException(1, "鐢ㄦ埛灏氭湭鐧诲綍"); + } + + if (auctionIds == null || auctionIds.size() == 0) { + throw new UserGoodsStorageException(1, "鍟嗗搧ID涓虹┖"); + } + + for (String auctionId : auctionIds) { + CommonGoods commonGoods = null; + if (goodsType == null) { + goodsType = Constant.SOURCE_TYPE_TAOBAO; + } + + if (goodsType == Constant.SOURCE_TYPE_JD) { + // 浜笢 + JDGoods jdGoods = JDApiUtil.queryGoodsDetail(Long.parseLong(auctionId)); + if (jdGoods == null) { + jdGoods = JDApiUtil.getGoodsDetail(Long.parseLong( auctionId)); + } + if (jdGoods == null) { + throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); + } + commonGoods = CommonGoodsFactory.create(jdGoods); + + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + // 鎷煎澶� + PDDGoodsDetail pddGoods = PinDuoDuoApiUtil.getGoodsDetail(Long.parseLong(auctionId)); + if (pddGoods == null) { + throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); + } + commonGoods = CommonGoodsFactory.create(pddGoods); + } else { + // 娣樺疂 + try { + // 鑾峰彇鍟嗗搧璇︽儏 + TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(auctionId); + commonGoods = CommonGoodsFactory.create(goodsBrief); + } catch (TaobaoGoodsDownException e) { + throw new UserGoodsStorageException(1, auctionId + "鍟嗗搧宸蹭笅鏋�"); + } + } + + if (commonGoods != null) { + try { + commonGoodsService.addOrUpdateCommonGoods(commonGoods); + } catch (CommonGoodsException e) { + e.printStackTrace(); + throw new UserGoodsStorageException(1, "鍟嗗搧淇℃伅鏇存柊澶辫触"); + } + + Long cid = commonGoods.getId(); + + UserGoodsStorage goodsStorage = userGoodsStorageMapper.getByUidAndCid(uid, cid); + + if (goodsStorage != null) { + // 鍒濆璇濈姸鎬� + goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); + goodsStorage.setUpdateTime(new Date()); + userGoodsStorageMapper.updateByPrimaryKeySelective(goodsStorage); + } else { + goodsStorage = new UserGoodsStorage(); + goodsStorage.setUid(uid); + ; + goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); + goodsStorage.setCommonGoods(commonGoods); + goodsStorage.setCreateTime(new Date()); + goodsStorage.setUpdateTime(new Date()); + userGoodsStorageMapper.insertSelective(goodsStorage); + } + } + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void addCommonGoods(Long uid, Set<Long> ids) throws UserGoodsStorageException { + + if (uid == null) { + throw new UserGoodsStorageException(1, "鐢ㄦ埛灏氭湭鐧诲綍"); + } + + if (ids == null || ids.size() == 0) { + throw new UserGoodsStorageException(1, "鍟嗗搧ID涓虹┖"); + } + + for (Long id : ids) { + CommonGoods commonGoods = commonGoodsService.selectByPrimaryKey(id); + if (commonGoods != null) { + UserGoodsStorage goodsStorage = userGoodsStorageMapper.getByUidAndCid(uid, id); + + if (goodsStorage != null) { + // 鍒濆璇濈姸鎬� + goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); + goodsStorage.setUpdateTime(new Date()); + userGoodsStorageMapper.updateByPrimaryKeySelective(goodsStorage); + } else { + goodsStorage = new UserGoodsStorage(); + goodsStorage.setUid(uid); + ; + goodsStorage.setState(UserGoodsStorage.STATE_NORMAL); + goodsStorage.setCommonGoods(commonGoods); + goodsStorage.setCreateTime(new Date()); + goodsStorage.setUpdateTime(new Date()); + userGoodsStorageMapper.insertSelective(goodsStorage); + } + } + } + } + + @Override + public JSONArray getMyStorage(int page, int pageSize, Long uid, Integer source) throws UserGoodsStorageException { + + JSONArray array = new JSONArray(); + + List<UserGoodsStorage> listStorage = listQueryByUid(page, pageSize, uid, source); + if (listStorage == null || listStorage.size() == 0) { + return array; + } + + if (source == null) { + source = Constant.SOURCE_TYPE_TAOBAO; + } + + List<TaoBaoGoodsBrief> listTaoKeGoods = null; + if (source == Constant.SOURCE_TYPE_TAOBAO) { + List<String> listGid = new ArrayList<>(); + for (UserGoodsStorage userGoodsStorage : listStorage) { + CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); + if (commonGoods == null) { + continue; + } + listGid.add(commonGoods.getGoodsId()); + } + + // API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭 + try { + listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid); + } catch (TaoKeApiException e) { + e.printStackTrace(); + } catch (TaobaoGoodsDownException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + SystemEnum system = userInfoService.getUserSystem(uid); + BigDecimal rate = manageService.getFanLiRate(UserLevelEnum.daRen, system); + Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()) + .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create(); + + for (UserGoodsStorage userGoodsStorage : listStorage) { + CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); + if (commonGoods == null) { + continue; + } + + int state = 0; + Integer goodsType = commonGoods.getGoodsType(); + + if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 && goodsType != null + && goodsType == Constant.SOURCE_TYPE_TAOBAO) { + state = 1; // 榛樿鍋滃敭 + String goodsId = commonGoods.getGoodsId(); + for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) { + String auctionId = taoKeGoods.getAuctionId(); + if (goodsId == auctionId || goodsId.equals(auctionId)) { + state = 0; // 鍦ㄥ敭 + break; + } + } + } + commonGoods.setState(state); + TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); + + // 鍒ゆ柇鏄惁宸插垎浜� + Integer storageState = userGoodsStorage.getState(); + if (storageState != null && storageState == UserGoodsStorage.STATE_SHARED) { + Integer goodsState = goodsBrief.getState(); + if (goodsState != null && goodsState != 1) { + goodsBrief.setState(2); // 宸插垎浜姸鎬� 浼樺厛鏄剧ず宸蹭笅鏋� + } + } + + 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); + } + + return array; + } + + @Override + public boolean isExistStorage(Long uid, String auctionId, Integer goodType) { + boolean state = false; + if (uid != null && auctionId != null) { + UserGoodsStorage userGoodsStorage = userGoodsStorageMapper.getByUidAndAuctionId(uid, auctionId, goodType); + if (userGoodsStorage != null) { + state = true; + } + } + 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, "閫夊搧搴撳晢鍝佷笉瀛樺湪"); + } + + 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<TaoBaoGoodsBrief> listGoodsBrief = new ArrayList<TaoBaoGoodsBrief>(); + + SystemEnum system = userInfoService.getUserSystem(uid); + + BigDecimal rate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,system); + for (UserGoodsStorage userGoodsStorage : listResult) { + CommonGoods commonGoods = userGoodsStorage.getCommonGoods(); + TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods); + listGoodsBrief.add(goodsBrief); + + BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(goodsBrief, rate, true); + totalMoney = MoneyBigDecimalUtil.add(totalMoney, money); + } + + ShareGoodsRecordDTO shareRecord = userShareGoodsRecordService.addRecordGoodsStorage(uid, listGoodsBrief, + listStorageID); + FileUploadResult uploadResult = new FileUploadResult(); + uploadResult.setUrl(shareRecord.getSharePictureUrl()); + + UserInfo user = userInfoService.selectByPKey(uid); + + JSONObject data = new JSONObject(); + data.put("revenue", listGoodsBrief.size() + "涓晢鍝侀浼板垎浜閲戯細楼" + totalMoney); + data.put("shareId", shareRecord.getRedisKey()); + data.put("shareImg", uploadResult); + data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareMultipleNotify.getKey(), user.getSystem())); + return data; + } + + @Override + public JSONObject createShareV2(Long uid, List<Long> listStorageID, boolean needDrawPicture) + 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; + } + } + } + + SystemEnum system = userInfoService.getUserSystem(uid); + + BigDecimal totalMoney = new BigDecimal(0.00); + List<CommonGoods> listCommonGoods = new ArrayList<CommonGoods>(); + + Integer goodsType = null; + BigDecimal rate = hongBaoManageService.getShareRate(UserLevelEnum.daRen,system); + 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, needDrawPicture); + 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) { + // 浜笢 + data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotifyJD.getKey(), system)); + } else if (goodsType == Constant.SOURCE_TYPE_PDD) { + // 鎷煎澶� + data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareNotifyPDD.getKey(), system)); + } else { + data.put("notifyDesc", configService.getValue(ConfigKeyEnum.goodsShareMultipleNotify.getKey(), system)); + } + return data; + } + +} -- Gitblit v1.8.0