From 47f157086a556d96e7bcfc9adfe17ecf7c154dfe Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 08 六月 2020 17:27:14 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into div

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudGoodsServiceImpl.java |  203 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 203 insertions(+), 0 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudGoodsServiceImpl.java
new file mode 100644
index 0000000..5fa8f95
--- /dev/null
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/cloud/UserCloudGoodsServiceImpl.java
@@ -0,0 +1,203 @@
+package com.yeshi.fanli.service.impl.user.cloud;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.springframework.stereotype.Service;
+
+import com.aliyun.openservices.ons.api.Message;
+import com.aliyun.openservices.ons.api.Producer;
+import com.yeshi.fanli.dao.mybatis.user.cloud.UserCloudGoodsMapper;
+import com.yeshi.fanli.dto.mq.user.UserTopicTagEnum;
+import com.yeshi.fanli.dto.mq.user.body.UserCloudMQMsg;
+import com.yeshi.fanli.dto.pdd.PDDGoodsDetail;
+import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
+import com.yeshi.fanli.dto.vip.goods.VIPGoodsInfo;
+import com.yeshi.fanli.entity.bus.user.cloud.UserCloudGoods;
+import com.yeshi.fanli.entity.goods.CommonGoods;
+import com.yeshi.fanli.entity.jd.JDGoods;
+import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.exception.goods.CommonGoodsException;
+import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
+import com.yeshi.fanli.exception.user.cloud.UserCloudGoodsException;
+import com.yeshi.fanli.log.LogHelper;
+import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
+import com.yeshi.fanli.service.inter.user.cloud.UserCloudGoodsService;
+import com.yeshi.fanli.service.inter.user.cloud.UserCloudManageService;
+import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.RedisManager;
+import com.yeshi.fanli.util.cache.JDGoodsCacheUtil;
+import com.yeshi.fanli.util.cache.PinDuoDuoCacheUtil;
+import com.yeshi.fanli.util.factory.CommonGoodsFactory;
+import com.yeshi.fanli.util.rocketmq.MQMsgBodyFactory;
+import com.yeshi.fanli.util.rocketmq.MQTopicName;
+import com.yeshi.fanli.util.suning.SuningApiUtil;
+import com.yeshi.fanli.util.vipshop.VipShopApiUtil;
+
+@Service
+public class UserCloudGoodsServiceImpl implements UserCloudGoodsService {
+
+	@Resource
+	private UserCloudGoodsMapper userCloudGoodsMapper;
+
+	@Resource
+	private RedisManager redisManager;
+
+	@Resource
+	private JDGoodsCacheUtil jdGoodsCacheUtil;
+
+	@Resource
+	private PinDuoDuoCacheUtil pinDuoDuoCacheUtil;
+
+	@Resource
+	private CommonGoodsService commonGoodsService;
+
+	@Resource
+	private UserCloudManageService userCloudManageService;
+
+	@Resource(name = "producer")
+	private Producer producer;
+
+	@Override
+	public void deleteByPrimaryKeyAndUid(Long id, Long uid) {
+		userCloudGoodsMapper.deleteByPrimaryKeyAndUid(id, uid);
+	}
+
+	@Override
+	public UserCloudGoods selectByPrimaryKey(Long id) {
+		return userCloudGoodsMapper.selectByPrimaryKey(id);
+	}
+
+	@Override
+	public void updateByPrimaryKeySelective(UserCloudGoods record) {
+		userCloudGoodsMapper.updateByPrimaryKeySelective(record);
+	}
+
+	@Override
+	public List<UserCloudGoods> query(int page, int pageSize, String key) {
+		return userCloudGoodsMapper.query((page - 1) * pageSize, pageSize, key);
+	}
+
+	@Override
+	public long count(String key) {
+		return userCloudGoodsMapper.count(key);
+	}
+
+	@Override
+	public List<UserCloudGoods> listByUid(long start, int count, Long uid) {
+		return userCloudGoodsMapper.listByUid(start, count, uid);
+	}
+
+	@Override
+	public List<UserCloudGoods> listByNotShare(Long uid) {
+		return userCloudGoodsMapper.listByNotShare(uid);
+	}
+
+	@Override
+	public long countByUid(Long uid) {
+		return userCloudGoodsMapper.countByUid(uid);
+	}
+
+	@Override
+	public UserCloudGoods getByUidAndGoods(Long uid, Long goodsId, Integer goodsType) {
+		return userCloudGoodsMapper.getByUidAndGoods(uid, goodsId, goodsType);
+	}
+
+	@Override
+	public UserCloudGoods addGoods(Long uid, Long goodsId, Integer goodsType, Long sellerId) throws UserCloudGoodsException {
+		if (uid == null)
+			throw new UserCloudGoodsException(1, "鐢ㄦ埛灏氭湭鐧诲綍");
+		if (goodsId == null || goodsType == null)
+			throw new UserCloudGoodsException(1, "绯荤粺鍙傛暟涓嶆纭�");
+	
+		CommonGoods commonGoods = null;
+		if (goodsType == Constant.SOURCE_TYPE_TAOBAO) { // 娣樺疂
+			try {
+				TaoBaoGoodsBrief goodsBrief = redisManager.getTaoBaoGoodsBrief(goodsId);
+				commonGoods = CommonGoodsFactory.create(goodsBrief);
+			} catch (TaobaoGoodsDownException e) {
+				throw new UserCloudGoodsException(1, goodsId + "鍟嗗搧宸蹭笅鏋�");
+			}
+		} else if (goodsType == Constant.SOURCE_TYPE_JD) { // 浜笢
+			JDGoods goods = jdGoodsCacheUtil.getGoodsInfo(goodsId);
+			if (goods == null)
+				throw new UserCloudGoodsException(1, goodsId + "鏈壘鍒板晢鍝佷俊鎭�");
+			commonGoods = CommonGoodsFactory.create(goods);
+		} else if (goodsType == Constant.SOURCE_TYPE_PDD) { // 鎷煎澶�
+			PDDGoodsDetail goods = pinDuoDuoCacheUtil.getGoodsInfo(goodsId);
+			if (goods == null)
+				throw new UserCloudGoodsException(1, goodsId + "鏈壘鍒板晢鍝佷俊鎭�");
+			commonGoods = CommonGoodsFactory.create(goods);
+		} else if (goodsType == Constant.SOURCE_TYPE_VIP) { // 鍞搧浼�
+			VIPGoodsInfo goods = VipShopApiUtil.getGoodsDetail(goodsId +"");
+			if (goods == null)
+				throw new UserCloudGoodsException(1, goodsId + "鏈壘鍒板晢鍝佷俊鎭�");
+			commonGoods = CommonGoodsFactory.create(goods);
+		} else if (goodsType == Constant.SOURCE_TYPE_SUNING) { // 鑻忓畞
+			SuningGoodsInfo goods = SuningApiUtil.getGoodsDetail(goodsId +"", sellerId + "");
+			if (goods == null)
+				throw new UserCloudGoodsException(1, goodsId + "鏈壘鍒板晢鍝佷俊鎭�");
+			commonGoods = CommonGoodsFactory.create(goods);
+		}
+
+		if (commonGoods == null) {
+			LogHelper.test("浜戝彂鍗曟湭鎵惧埌鍟嗗搧璇︽儏锛宨d=" + goodsId + "type=" + goodsType);
+			throw new UserCloudGoodsException(1, "鍟嗗搧淇℃伅鑾峰彇澶辫触");
+		}
+
+		try {
+			commonGoodsService.addOrUpdateCommonGoods(commonGoods);
+		} catch (CommonGoodsException e) {
+			LogHelper.errorDetailInfo(e);
+			throw new UserCloudGoodsException(1, "鍟嗗搧淇℃伅鏇存柊澶辫触");
+		}
+		
+		UserCloudGoods result = null;
+		UserCloudGoods cloudGoods = userCloudGoodsMapper.getByUidAndCommonGoodsId(uid, commonGoods.getId());
+		if (cloudGoods != null) {
+			result = cloudGoods;
+			
+			UserCloudGoods update = new UserCloudGoods();
+			update.setId(cloudGoods.getId());
+			update.setState(UserCloudGoods.STATE_NORMAL);
+			update.setUpdateTime(new Date());
+			userCloudGoodsMapper.updateByPrimaryKeySelective(update);
+		} else {
+			cloudGoods = new UserCloudGoods();
+			cloudGoods.setUid(uid);
+			cloudGoods.setState(UserCloudGoods.STATE_NORMAL);
+			cloudGoods.setCommonGoods(commonGoods);
+			cloudGoods.setCreateTime(new Date());
+			cloudGoods.setUpdateTime(new Date());
+			userCloudGoodsMapper.insertSelective(cloudGoods);
+			
+			result = cloudGoods;
+		}
+		return result;
+	}
+
+	@Override
+	public void sendGoodsMQMsg(Long uid) {
+		if (Constant.IS_TEST) {
+			return;
+		}
+
+		List<UserCloudGoods> list = userCloudGoodsMapper.listByNotShare(uid);
+		if (list == null || list.size() == 0) {
+			return;
+		}
+
+		long deliverTime = java.lang.System.currentTimeMillis();
+		for (UserCloudGoods cloudGoods : list) {
+			UserCloudMQMsg msg = new UserCloudMQMsg(uid, cloudGoods.getId() + "", UserCloudMQMsg.TYPE_STORE);
+			Message message = MQMsgBodyFactory.create(MQTopicName.TOPIC_USER, UserTopicTagEnum.userCloud, msg);
+			message.setStartDeliverTime(deliverTime);
+			producer.send(message);
+			// 姣�5鍒嗛挓鏌ヨ涓�娆�
+			deliverTime = deliverTime + 1000 * 60 * 5;
+		}
+	}
+
+}

--
Gitblit v1.8.0