From 98b1a0affd69bbe63223c21fdd2c404e8bedfccb Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 20 五月 2020 17:25:08 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/div' into 2.1.2

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/goods/RecommendUserGoodsServiceImpl.java |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/RecommendUserGoodsServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/RecommendUserGoodsServiceImpl.java
index 9d126c6..0b8cba9 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/RecommendUserGoodsServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/goods/RecommendUserGoodsServiceImpl.java
@@ -18,6 +18,7 @@
 import com.yeshi.fanli.exception.goods.RecommendUserGoodsException;
 import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
 import com.yeshi.fanli.service.inter.goods.RecommendUserGoodsService;
+import com.yeshi.fanli.util.StringUtil;
 
 @Service
 public class RecommendUserGoodsServiceImpl implements RecommendUserGoodsService {
@@ -29,7 +30,7 @@
 	@Resource
 	private CommonGoodsService commonGoodsService;
 
-	@Transactional
+	@Transactional(rollbackFor=Exception.class)
 	@Override
 	public void addRecommend(Long uid, String device, String recommendDesc, List<CommonGoods> goodsList)
 			throws RecommendUserGoodsException {
@@ -39,7 +40,8 @@
 		RecommendUserGoods goods = new RecommendUserGoods();
 		goods.setCreateTime(new Date());
 		goods.setRecommendDesc(recommendDesc);
-		goods.setUser(new UserInfo(uid));
+		if (uid != null)
+			goods.setUser(new UserInfo(uid));
 		goods.setDevice(device);
 		recommendUserGoodsMapper.insertSelective(goods);
 		for (CommonGoods commonGoods : goodsList)
@@ -75,7 +77,7 @@
 	public RecommendUserGoods getLatestRecommendUserGoods(Long uid) {
 		return recommendUserGoodsMapper.getLatestRecommendUserGoods(uid);
 	}
-	
+
 	@Override
 	public RecommendUserGoods getLatestRecommendUserGoodsByDevice(String device) {
 		return recommendUserGoodsMapper.getLatestRecommendUserGoodsByDevice(device);
@@ -85,10 +87,25 @@
 	public List<RecommendUserGoods> listRecommendGoodsByDevice(String device, int page, int pageSize) {
 		return recommendUserGoodsMapper.listRecommendGoodsByDevice(device, (page - 1) * pageSize, pageSize);
 	}
-	
+
 	@Override
 	public long countRecommendGoodsByDevice(String device) {
 		return recommendUserGoodsMapper.countRecommendGoodsByDevice(device);
 	}
 
+	@Override
+	public void syncDeviceAndUid(Long uid, String targetDevice) {
+
+		List<RecommendUserGoods> list = recommendUserGoodsMapper.listRecommendGoods(uid, 0, 20);
+		for (RecommendUserGoods ru : list) {
+			if (StringUtil.isNullOrEmpty(ru.getDevice())) {
+				RecommendUserGoods update = new RecommendUserGoods();
+				update.setId(ru.getId());
+				update.setDevice(targetDevice);
+				recommendUserGoodsMapper.updateByPrimaryKeySelective(update);
+			}
+		}
+
+	}
+
 }

--
Gitblit v1.8.0