From 4cb15e222cd7d099d533ccbeb7f9a8cd99bf180c Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 25 十二月 2018 16:35:18 +0800
Subject: [PATCH] 替换原来老的资金详情

---
 fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserShareGoodsRecordServiceImpl.java |  280 ++++++++++++++++++++++---------------------------------
 1 files changed, 112 insertions(+), 168 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 f07d543..9192eb4 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
@@ -4,6 +4,7 @@
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -15,6 +16,7 @@
 
 import org.springframework.core.task.TaskExecutor;
 import org.springframework.stereotype.Service;
+import org.yeshi.utils.DateUtil;
 import org.yeshi.utils.HttpUtil;
 import org.yeshi.utils.JsonUtil;
 import org.yeshi.utils.QRCodeUtil;
@@ -36,6 +38,7 @@
 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.TaoKeApiException;
 import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
 import com.yeshi.fanli.service.inter.config.ConfigService;
 import com.yeshi.fanli.service.inter.goods.CommonGoodsService;
@@ -51,6 +54,7 @@
 import com.yeshi.fanli.util.StringUtil;
 import com.yeshi.fanli.util.factory.CommonGoodsFactory;
 import com.yeshi.fanli.util.taobao.TaoBaoUtil;
+import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
 
 @Service
 public class UserShareGoodsRecordServiceImpl implements UserShareGoodsRecordService {
@@ -261,7 +265,7 @@
 	 * @throws UserShareGoodsRecordException
 	 */
 	@Override
-	public JSONObject save(Long uid, ShareSourceTypeEnum source, String title, List<TaoBaoGoodsBrief> listGoods) throws UserShareGoodsRecordException {
+	public Map<String,Object> save(Long uid, ShareSourceTypeEnum source, String title, List<TaoBaoGoodsBrief> listGoods) throws UserShareGoodsRecordException {
 		
 		if (listGoods == null || listGoods.size() < 0) {
 			throw new UserShareGoodsRecordException(1, "鍒嗕韩鍟嗗搧鏁伴噺涓嶈冻");
@@ -289,13 +293,13 @@
 		userShareGoodsRecordMapper.insertSelective(userShareGoodsRecord);
 		
 		
-		JSONObject data = new JSONObject();
+		Map<String,Object> map = new HashMap<String,Object>();
 		// 澶氫釜鍟嗗搧鍒嗕韩
 		FileUploadResult loadResult = multipleGoodsShare(userShareGoodsRecord, listGoods);
-		data.put("loadResult", loadResult);
-		data.put("shareId", userShareGoodsRecord.getId());
+		map.put("loadResult", loadResult);
+		map.put("shareId", userShareGoodsRecord.getId());
 		
-		return data;
+		return map;
 	}
 	
 	/**
@@ -483,88 +487,72 @@
 	public JSONObject getGoodsGroup(Long recordId) throws UserShareGoodsRecordException {
 		
 		JSONArray array = new JSONArray();
-		List<CommonGoods> listUpadteCommonGoods = new ArrayList<CommonGoods>();
 
 		List<UserShareGoodsGroup> list = userShareGoodsGroupService.listByRecordId(recordId);
-		if (list != null && list.size() > 0) {
+		
+		List<Long> listGid = new ArrayList<Long>();
+		for (UserShareGoodsGroup goodsGroup : list) {
+			CommonGoods commonGoods = goodsGroup.getCommonGoods();
+			if (commonGoods == null) {
+				continue;
+			}
+			listGid.add(commonGoods.getGoodsId());
+		}
+		
+		// API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭
+		List<TaoBaoGoodsBrief> listTaoKeGoods = null;
+		try {
+			listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
+		} catch (TaoKeApiException e) {
+			e.printStackTrace();
+		} catch (TaobaoGoodsDownException e) {
+			e.printStackTrace();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		
 
-			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();
 
-			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();
-							}
-						}
+		BigDecimal shareRate = hongBaoManageService.getShareRate(java.lang.System.currentTimeMillis());
+		
+		for (UserShareGoodsGroup goodsGroup : list) {
+			CommonGoods commonGoods = goodsGroup.getCommonGoods();
+			if (commonGoods == null) {
+				continue;
+			}
+			
+			if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 ) {
+				int state = 1;  // 榛樿鍋滃敭
+				Long goodsId = commonGoods.getGoodsId();
+				for (TaoBaoGoodsBrief taoKeGoods: listTaoKeGoods) {
+					Long auctionId = taoKeGoods.getAuctionId();
+					if (goodsId == auctionId || goodsId.equals(auctionId)) {
+						state = 0; // 鍦ㄥ敭
+						break;
 					}
 				}
-
-				if (goodsBrief == null) {
-					goodsBrief = TaoBaoUtil.convert(commonGoods);
-				} 
-
-				// 鏀瑰彉鍥剧墖灏哄
-				String pictUrl = goodsBrief.getPictUrl();
-				if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
-					goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
-				}
-				
-				userShareGoodsGroup.setId(null);
-				userShareGoodsGroup.setBrowseTime(null);
-				userShareGoodsGroup.setCreateTime(null);
-				userShareGoodsGroup.setUpdateTime(null);
-				userShareGoodsGroup.setRecordId(null);
-				
-				dataObject.put("todayBrowse",userShareGoodsGroup.getTodayBrowse() );
-				dataObject.put("totalBrowse",userShareGoodsGroup.getTotalBrowse() );
-				dataObject.put("totalOrder", userShareGoodsGroup.getTotalOrder());
-				dataObject.put("totalMoney", "楼"+userShareGoodsGroup.getTotalMoney());
-				dataObject.put("goods", gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null)));
-				array.add(dataObject);
+				commonGoods.setState(state);
 			}
+			
+			TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
+			
+			// 浠婃棩娴忚璁板綍澶勭悊
+			Date date = new Date();
+			Date browseTime = goodsGroup.getBrowseTime();
+			if (!DateUtil.isSameDay(browseTime, date)) {
+				goodsGroup.setTodayBrowse(0); // 涓嶆槸鍚屼竴澶╂祻瑙堣褰曡缃�0
+			}
+			
+			
+			JSONObject dataObject = new JSONObject();
+			dataObject.put("todayBrowse",goodsGroup.getTodayBrowse() );
+			dataObject.put("totalBrowse",goodsGroup.getTotalBrowse() );
+			dataObject.put("totalOrder", goodsGroup.getTotalOrder());
+			dataObject.put("totalMoney", "楼"+goodsGroup.getTotalMoney());
+			dataObject.put("goods", gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, shareRate+"", null)));
+			array.add(dataObject);
 		}
 		
 		String title = "";
@@ -577,21 +565,6 @@
 		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;
 	}
 
@@ -599,83 +572,68 @@
 	@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();
+			List<Long> listGid = new ArrayList<Long>();
+			for (UserShareGoodsGroup goodsGroup : list) {
+				CommonGoods commonGoods = goodsGroup.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;
-					    			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();
-							}
+				listGid.add(commonGoods.getGoodsId());
+			}
+			
+			// API缃戠粶鎺ュ彛楠岃瘉鏄惁鍦ㄥ敭
+			List<TaoBaoGoodsBrief> listTaoKeGoods = null;
+			try {
+				listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
+			} catch (TaoKeApiException e) {
+				e.printStackTrace();
+			} catch (TaobaoGoodsDownException e) {
+				e.printStackTrace();
+			} catch (Exception e) {
+				e.printStackTrace();
+			}
+			
+			
+			Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
+					.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
+			
+			BigDecimal shareRate = hongBaoManageService.getShareRate(java.lang.System.currentTimeMillis());
+			
+			for (UserShareGoodsGroup goodsGroup : list) {
+				CommonGoods commonGoods = goodsGroup.getCommonGoods();
+				if (commonGoods == null) {
+					continue;
+				}
+				
+				if (listTaoKeGoods != null && listTaoKeGoods.size() > 0 ) {
+					int 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);
 				}
-
-				if (goodsBrief == null) {
-					goodsBrief = TaoBaoUtil.convert(commonGoods);
-				} 
+				
+				TaoBaoGoodsBrief goodsBrief = TaoBaoUtil.convert(commonGoods);
 				
 				if (goodsBrief.getCouponLeftCount() < 1 || StringUtil.isNullOrEmpty(goodsBrief.getCouponInfo())) {
     				goodsBrief.setState(1); // 宸叉姠鍏�
     			}
 				
-				// 鏀瑰彉鍥剧墖灏哄
-				String pictUrl = goodsBrief.getPictUrl();
-				if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
-					goodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
-				}
-				
-				TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion, null);
+				TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, shareRate +"", null);
 				array.add(gson.toJson(taoBaoGoodsBriefExtra));
 			}
+
 		}
 		
 		String title = "";
@@ -688,20 +646,6 @@
 		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;
 	}

--
Gitblit v1.8.0