From 205f8ba403095b4894d026f800d2651223c19d00 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期三, 12 十二月 2018 17:44:11 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java |  183 ++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 170 insertions(+), 13 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java
index 23a1c21..7b63d14 100644
--- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java
+++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java
@@ -33,6 +33,7 @@
 import com.yeshi.fanli.entity.bus.user.UserInfo;
 import com.yeshi.fanli.entity.goods.CommonGoods;
 import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
+import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
 import com.yeshi.fanli.exception.goods.CommonGoodsException;
 import com.yeshi.fanli.exception.share.UserShareGoodsRecordException;
 import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
@@ -40,6 +41,7 @@
 import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
 import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
 import com.yeshi.fanli.service.inter.user.UserAccountService;
+import com.yeshi.fanli.service.inter.user.UserGoodsStorageService;
 import com.yeshi.fanli.service.inter.user.UserShareGoodsGroupService;
 import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
 import com.yeshi.fanli.util.AESUtil;
@@ -79,6 +81,9 @@
 	
 	@Resource
 	private HongBaoManageService hongBaoManageService;
+	
+	@Resource
+	private UserGoodsStorageService userGoodsStorageService;
 
 	@Override
 	public int insert(UserShareGoodsRecord record) {
@@ -196,6 +201,32 @@
 		return list;
 	}
 	
+
+	@Override
+	public void saveDetail(Long uid, Long auctionId, String type) throws UserShareGoodsRecordException {
+		
+		if (auctionId == null) {
+			throw new UserShareGoodsRecordException(1, "鍒嗕韩鍟嗗搧涓嶈兘涓虹┖");
+		}
+		
+		if (uid == null) {
+			throw new UserShareGoodsRecordException(1, "鐢ㄦ埛ID涓嶈兘涓虹┖");
+		}
+		
+		TaoBaoGoodsBrief goodsBrief = null;
+		try {
+			goodsBrief = redisManager.getTaoBaoGoodsBrief(auctionId);
+		} catch (TaobaoGoodsDownException e) {
+			throw new UserShareGoodsRecordException(1, "鍟嗗搧宸蹭笅鏋�");
+		}
+		
+		UserShareGoodsRecord userShareGoodsRecord = new UserShareGoodsRecord();
+		userShareGoodsRecord.setUid(uid);
+		userShareGoodsRecord.setSource(ShareSourceTypeEnum.goodsDetail);
+		userShareGoodsRecord.setShareState(1);// 宸插垎浜垚鍔�
+		// 鍗曚釜鍟嗗搧鍒嗕韩
+		singleGoodsShare(userShareGoodsRecord, goodsBrief);
+	}
 	
 	@Override
 	public void save(Long uid, ShareSourceTypeEnum source, String title, TaoBaoGoodsBrief taoBaoGoodsBrief) throws UserShareGoodsRecordException {
@@ -227,7 +258,7 @@
 	 * @throws UserShareGoodsRecordException
 	 */
 	@Override
-	public FileUploadResult save(Long uid, ShareSourceTypeEnum source, String title, List<TaoBaoGoodsBrief> listGoods) throws UserShareGoodsRecordException {
+	public JSONObject save(Long uid, ShareSourceTypeEnum source, String title, List<TaoBaoGoodsBrief> listGoods) throws UserShareGoodsRecordException {
 		
 		if (listGoods == null || listGoods.size() < 0) {
 			throw new UserShareGoodsRecordException(1, "鍒嗕韩鍟嗗搧鏁伴噺涓嶈冻");
@@ -249,13 +280,19 @@
 		userShareGoodsRecord.setPicture(listGoods.get(0).getPictUrl());
 		
 		Date date = new Date();
+		userShareGoodsRecord.setShareState(0); // 鍒濆鏈垎浜�
 		userShareGoodsRecord.setCreateTime(date);
 		userShareGoodsRecord.setUpdateTime(date);
 		userShareGoodsRecordMapper.insertSelective(userShareGoodsRecord);
 		
-		// 澶氫釜鍟嗗搧鍒嗕韩
-		return multipleGoodsShare(userShareGoodsRecord, listGoods);
 		
+		JSONObject data = new JSONObject();
+		// 澶氫釜鍟嗗搧鍒嗕韩
+		FileUploadResult loadResult = multipleGoodsShare(userShareGoodsRecord, listGoods);
+		data.put("loadResult", loadResult);
+		data.put("shareId", userShareGoodsRecord.getId());
+		
+		return data;
 	}
 	
 	/**
@@ -458,11 +495,9 @@
 	
 	@Override
 	public JSONObject getGoodsGroup(Long recordId) throws UserShareGoodsRecordException {
-		UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId);
 		
-		List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
-
 		JSONArray array = new JSONArray();
+		List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
 
 		List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
 		if (list != null && list.size() > 0) {
@@ -526,20 +561,24 @@
 				} 
 
 				// 鏀瑰彉鍥剧墖灏哄
-				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, proportion, null));
-
-				dataObject.put("groupId", userShareGoodsGroup.getId());
-				dataObject.put("goods", json);
+				
+				userShareGoodsGroup.setId(null);
+				userShareGoodsGroup.setBrowseTime(null);
+				userShareGoodsGroup.setCreateTime(null);
+				userShareGoodsGroup.setUpdateTime(null);
+				userShareGoodsGroup.setRecordId(null);
+				dataObject.put("group", gson.toJson(userShareGoodsGroup));
+				dataObject.put("goods", gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null)));
 				array.add(dataObject);
 			}
 		}
 		
 		String title = "";
+		UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId);
 		if(userShareGoodsRecord != null) {
 			title = userShareGoodsRecord.getTitle();
 		}
@@ -566,4 +605,122 @@
 		return data;
 	}
 
+	
+	@Override
+	public JSONObject getGoodsGroupDetail(Long recordId) throws UserShareGoodsRecordException {
+		
+		List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
+
+		JSONArray array = new JSONArray();
+		
+		List<UserShareGoodsGroup> list = userShareGoodsGroupService.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;
+				// 鏇存柊涓�涓皬鏃朵箣鍐呯殑鍟嗗搧涓嶅啀鏇存柊
+				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;
+					    			if (goodsBrief.getCouponLeftCount() < 1 || StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())) {
+					    				goodsBrief.setState(1); // 宸叉姠鍏�
+					    			}
+					    			
+					    			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 = goodsBrief.getPictUrl();
+				if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
+					goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
+				}
+				
+				TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null);
+				array.add(gson.toJson(taoBaoGoodsBriefExtra));
+			}
+		}
+		
+		String title = "";
+		UserShareGoodsRecord userShareGoodsRecord = userShareGoodsRecordMapper.selectByPrimaryKey(recordId);
+		if(userShareGoodsRecord != null) {
+			title = userShareGoodsRecord.getTitle();
+		}
+		
+		JSONObject data = new JSONObject();
+		data.put("title", title);
+		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;
+	}
+
+	@Override
+	public void updateShareRecord (Long shareId) throws UserShareGoodsRecordException {
+		UserShareGoodsRecord shareRecord = userShareGoodsRecordMapper.selectByPrimaryKey(shareId);
+		if (shareRecord == null) {
+			throw new UserShareGoodsRecordException(1, "鍒嗕韩璁板綍涓嶅瓨鍦�");
+		}
+		
+		userGoodsStorageService.updateShareState(shareId);
+	}
 }

--
Gitblit v1.8.0