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/user/UserShareGoodsGroupServiceImpl.java |  262 ++++++++++++++++++---------------------------------
 1 files changed, 94 insertions(+), 168 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
index 6771f01..e0a57c7 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsGroupServiceImpl.java
@@ -1,50 +1,30 @@
 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.Map;
 
 import javax.annotation.Resource;
 
-import net.sf.json.JSONArray;
-import net.sf.json.JSONObject;
-
-import org.springframework.core.task.TaskExecutor;
 import org.springframework.stereotype.Service;
 import org.yeshi.utils.DateUtil;
-import org.yeshi.utils.JsonUtil;
-import org.yeshi.utils.taobao.TbImgUtil;
 
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
 import com.yeshi.fanli.dao.mybatis.share.UserShareGoodsGroupMapper;
+import com.yeshi.fanli.dto.HongBao;
 import com.yeshi.fanli.entity.bus.share.UserShareGoodsGroup;
-import com.yeshi.fanli.entity.goods.CommonGoods;
-import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.bus.share.UserShareGoodsRecord.ShareSourceTypeEnum;
 import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
-import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
 import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
-import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
 import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
+import com.yeshi.fanli.util.Constant;
 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;
-import com.yeshi.fanli.util.taobao.TaoBaoUtil;
 
 @Service
 public class UserShareGoodsGroupServiceImpl implements UserShareGoodsGroupService {
 
-	@Resource(name = "taskExecutor")
-	private TaskExecutor executor;
-	
 	@Resource
 	private HongBaoManageService hongBaoManageService;
-	
-	@Resource
-	private RedisManager redisManager;
 	
 	@Resource
 	private CommonGoodsService commonGoodsService;
@@ -84,7 +64,7 @@
 
 	@Override
 	public UserShareGoodsGroup getSingleGoods(Long cid, Long uid) {
-		return userShareGoodsGroupMapper.getSingleGoods(cid, uid);
+		return userShareGoodsGroupMapper.getSingleGoods(ShareSourceTypeEnum.goodsDetail,cid, uid );
 	}
 
 	@Override
@@ -93,49 +73,58 @@
 	}
 
 	@Override
-	public UserShareGoodsGroup getNewestRecord(Long uid, Long auctionId) {
-		return userShareGoodsGroupMapper.getNewestRecord(uid, auctionId);
+	public UserShareGoodsGroup getNewestRecord(Long uid, Long auctionId, Integer goodsType) {
+		return userShareGoodsGroupMapper.getNewestRecord(uid, auctionId, goodsType);
 	}
 
 	
 	/**
-	 * 鏇存柊娴忚璁板綍鏁版嵁
-	 * @param shareId 鍒嗕韩id
-	 * @param count 娴忚娆℃暟
+	 * 鏇存柊璁㈠崟璁板綍鏁版嵁
+	 * @param uid
+	 * @param auctionId
 	 */
 	@Override
-	public void updateBrowseRecord (Long shareId, int count) throws UserShareGoodsRecordException{
-
-		if (shareId == null) {
-			throw new UserShareGoodsRecordException(1, "鍒嗕韩id涓虹┖");
+	public void updateOrderRecord (HongBao hongBao, int goodsType) throws UserShareGoodsRecordException{
+		
+		if (hongBao == null) {
+			throw new UserShareGoodsRecordException(1, "hongBao涓嶈兘涓虹┖");
 		}
 		
-		List<UserShareGoodsGroup> list = listByRecordId(shareId);
-		if (list == null || list.size() == 0) {
-			throw new UserShareGoodsRecordException(1, "鍒嗕韩鍟嗗搧宸蹭笉瀛樺湪");
+		if (hongBao.getUserInfo() == null) {
+			throw new UserShareGoodsRecordException(1, "鐢ㄦ埛淇℃伅涓嶈兘涓虹┖");
 		}
 		
-		List<UserShareGoodsGroup> listUpdate = new ArrayList<UserShareGoodsGroup>();
+		Long uid = hongBao.getUserInfo().getId();
+		if (uid == null) {
+			throw new UserShareGoodsRecordException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
+		}
 		
-		for (UserShareGoodsGroup group: list) {
-			// 娉ㄦ剰锛� 淇敼璁板綍鏁版嵁銆佷絾涓嶅彲淇敼鏇存柊璁剧疆
-			UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
+		if (hongBao.getAuctionId() == null) {
+			throw new UserShareGoodsRecordException(1, "鍟嗗搧ID涓嶈兘涓虹┖");
+		}
+		
+		UserShareGoodsGroup newestRecord = getNewestRecord(uid, hongBao.getAuctionId(), goodsType);
+		
+		if (newestRecord != null) {
+			// 鏇存柊璁㈠崟鏁伴噺
+			UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
+			Integer totalOrder = newestRecord.getTotalOrder();
 			
-			shareGoodsGroup.setTotalBrowse(group.getTotalBrowse() + count);
-			
-			Date browseTime = group.getBrowseTime();
-			if (DateUtil.isSameDay(browseTime, new Date())) {
-				shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + count);
-			} else {
-				shareGoodsGroup.setTodayBrowse(count);
-				shareGoodsGroup.setBrowseTime(new Date());
+			if (totalOrder == null) {
+				totalOrder = 0;
 			}
+			shareGoodsGroup.setTotalOrder(totalOrder + 1);
 			
-			listUpdate.add(shareGoodsGroup);
+			// 鏇存柊棰勮鏀剁泭 
+			BigDecimal totalMoney = newestRecord.getTotalMoney();
+			if (totalMoney == null) {
+				totalMoney = new BigDecimal(0);
+			}
+			BigDecimal resultMoney = MoneyBigDecimalUtil.add(totalMoney, hongBao.getMoney());
+			shareGoodsGroup.setTotalMoney(resultMoney);
+			
+			updateByPrimaryKeySelective(shareGoodsGroup);
 		}
-		
-		userShareGoodsGroupMapper.updateBatchSelective(listUpdate);
-		
 	}
 	
 	
@@ -145,138 +134,75 @@
 	 * @param auctionId
 	 */
 	@Override
-	public void updateOrderRecord (Long uid, TaoBaoGoodsBrief taoBaoGoodsBrief, int count) 
+	public void updateBrowseRecord (Long uid, Long auctionId, int count) 
 			throws UserShareGoodsRecordException{
 		
 		if (uid == null) {
 			throw new UserShareGoodsRecordException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
 		}
 		
-		if (taoBaoGoodsBrief == null) {
-			throw new UserShareGoodsRecordException(1, "鍟嗗搧涓嶈兘涓虹┖");
+		if (auctionId == null) {
+			throw new UserShareGoodsRecordException(1, "鍟嗗搧Id涓嶈兘涓虹┖");
 		}
 		
-		UserShareGoodsGroup newestRecord = getNewestRecord(uid, taoBaoGoodsBrief.getAuctionId());
+		UserShareGoodsGroup group = getNewestRecord(uid, auctionId, Constant.SOURCE_TYPE_TAOBAO);
 		
-		if (newestRecord != null) {
-			// 娉ㄦ剰锛� 淇敼璁板綍鏁版嵁銆佷絾涓嶅彲淇敼鏇存柊璁剧疆
-			UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(newestRecord.getId());
-			shareGoodsGroup.setTotalOrder(newestRecord.getTotalOrder() + count);
+		if (group != null) {
+			UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
+			// 绱娴忚
+			Integer totalBrowse = group.getTotalBrowse();
+			if (totalBrowse == null) {
+				totalBrowse = 0;
+			}
+			shareGoodsGroup.setTotalBrowse(totalBrowse + count);
 			
-			// 鍗曚釜鍟嗗搧棰勮閲戦
-			String rateStr = hongBaoManageService.get("hongbao_goods_proportion");
-			BigDecimal money = TaoBaoUtil.getGoodsHongBaoMoney(taoBaoGoodsBrief, new BigDecimal(rateStr));
+			// 浠婃棩娴忚
+			Date date = new Date();
+			Date browseTime = group.getBrowseTime();
+			if (DateUtil.isSameDay(browseTime, date)) {
+				shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + count);
+			} else {
+				shareGoodsGroup.setTodayBrowse(count);
+			}
+			shareGoodsGroup.setBrowseTime(date);
 			
-			// 鏇存柊棰勮鏀剁泭 
-			BigDecimal resultMoney = MoneyBigDecimalUtil.mul(new BigDecimal(shareGoodsGroup.getTotalOrder()), money);
-			shareGoodsGroup.setTotalMoney(resultMoney);
-			
-			updateByPrimaryKeySelective(shareGoodsGroup);
+			userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
 		}
 	}
 	
+	
+	
 	@Override
-	public JSONObject getGoodsGroup(Long recordId) throws UserShareGoodsRecordException {
+	public void updateBrowseNum(Long uid, Long id, int goodsType) throws UserShareGoodsRecordException{
 		
-		List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
-
-		JSONArray array = new JSONArray();
-
-		List<UserShareGoodsGroup> list = listByRecordId(recordId);
-		if (list != null && list.size() > 0) {
-
-			Date nowDate = new Date();
-			long nh = 1000 * 60 * 60;
-			long nd = 1000 * 24 * 60 * 60;
-
-			Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
-					.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
-
-			Map<String, String> map = hongBaoManageService.convertMap();
-			String proportion = map.get("hongbao_goods_proportion");
-
-			for (UserShareGoodsGroup userShareGoodsGroup : list) {
-				CommonGoods commonGoods = userShareGoodsGroup.getCommonGoods();
-				if (commonGoods == null) {
-					continue;
-				}
-
-				TaoBaoGoodsBrief goodsBrief = null;
-				JSONObject dataObject = new JSONObject();
-
-				// 鏇存柊涓�涓皬鏃朵箣鍐呯殑鍟嗗搧涓嶅啀鏇存柊
-				Integer goodsState = commonGoods.getState();
-				// 鐘舵�佹湭涓嬫灦鏃惰繘琛屾洿鏂�
-				if (goodsState != null && (goodsState != 1 || !goodsState.equals(1))) {
-					Date updateTime = commonGoods.getUpdateTime();
-					if (updateTime != null) {
-						
-						// 璁$畻宸灏戝皬鏃�
-						long diff = nowDate.getTime() - updateTime.getTime();
-						long day = diff / nd;
-					    long hour = diff % nd / nh;
-					    if (hour > 1 || day > 0 ) {
-					    	try {
-					    		if (commonGoods.getGoodsType() == CommonGoods.GOODS_TYPE_TB) {
-					    			goodsBrief = redisManager.getTaoBaoGoodsBrief(commonGoods.getGoodsId());
-					    		
-					    			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(goodsState);
-								listUpadteCommonGoods.add(commonGoods);
-								e.printStackTrace();
-							}
-						}
-					}
-				}
-
-				if (goodsBrief == null) {
-					goodsBrief = TaoBaoUtil.convert(commonGoods);
-				} 
-
-				// 鏀瑰彉鍥剧墖灏哄
-				String pictUrl = commonGoods.getPicture();
-				if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
-					commonGoods.setPicture(TbImgUtil.getTBSize320Img(pictUrl));
-				}
-
-				String json = gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null));
-
-				dataObject.put("groupId", userShareGoodsGroup.getId());
-				dataObject.put("goods", json);
-				array.add(dataObject);
+		if (uid == null) {
+			throw new UserShareGoodsRecordException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
+		}
+		
+		if (id == null) {
+			throw new UserShareGoodsRecordException(1, "鍟嗗搧Id涓嶈兘涓虹┖");
+		}
+		
+		UserShareGoodsGroup group = getNewestRecord(uid, id, goodsType);
+		if (group != null) {
+			UserShareGoodsGroup shareGoodsGroup = new UserShareGoodsGroup(group.getId());
+			// 绱娴忚
+			Integer totalBrowse = group.getTotalBrowse();
+			if (totalBrowse == null) {
+				totalBrowse = 0;
 			}
-
+			shareGoodsGroup.setTotalBrowse(totalBrowse + 1);
+			
+			// 浠婃棩娴忚
+			Date date = new Date();
+			Date browseTime = group.getBrowseTime();
+			if (DateUtil.isSameDay(browseTime, date)) {
+				shareGoodsGroup.setTodayBrowse(group.getTodayBrowse() + 1);
+			} else {
+				shareGoodsGroup.setTodayBrowse(1);
+			}
+			shareGoodsGroup.setBrowseTime(date);
+			userShareGoodsGroupMapper.updateByPrimaryKeySelective(shareGoodsGroup);
 		}
-		
-		JSONObject data = new JSONObject();
-		data.put("count", list.size());
-		data.put("result_list", array);
-
-		if (listUpadteCommonGoods.size() > 0) {
-			executor.execute(new Runnable() {
-				@Override
-				public void run() {
-					try {
-						// 鏇存柊绠�鐗堜俊鎭�
-						commonGoodsService.updateBatchCommonGoods(listUpadteCommonGoods);
-					} catch (Exception e) {
-						e.printStackTrace();
-					}
-				}
-			});
-		}
-		
-		return data;
 	}
-
 }

--
Gitblit v1.8.0