From 4114e871bcb3dce771b6aed64a1027d0bbb95ca6 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 16 五月 2019 15:28:37 +0800
Subject: [PATCH] 增加动态用户

---
 fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java |  189 +++++++++++++++++++++++++++++------------------
 1 files changed, 117 insertions(+), 72 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
index 8e1e161..7b95163 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/ShareController.java
@@ -9,6 +9,7 @@
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 
+import org.springframework.core.task.TaskExecutor;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -71,6 +72,9 @@
 @RequestMapping("api/v1/share")
 public class ShareController {
 
+	@Resource(name = "taskExecutor")
+	private TaskExecutor executor;
+	
 	@Resource
 	private ShareGoodsService shareGoodsService;
 
@@ -219,36 +223,40 @@
 
 			// 娣诲姞鍒嗕韩璁板綍
 			BigDecimal rate = hongBaoManageService.getShareRate();
-			UserShareGoodsHistory history = new UserShareGoodsHistory();
-			history.setTkCode(taoBaoLink.getTaoToken());
-			history.setLink(taoBaoLink.getClickUrl());
-			history.setQuanLink(taoBaoLink.getCouponLink());
-
-			history.setCreateTime(new Date());
-			history.setGoodsId(taoBaoLink.getGoods().getAuctionId());
-			history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
-			history.setHongbao(TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate));
-			List<String> imgList = taoBaoLink.getGoods().getImgList();
-			if (imgList == null) {
-				imgList = new ArrayList<>();
-			}
-			history.setPictures(JsonUtil.getGson().toJson(imgList));
-			history.setUser(new UserInfo(uid));
-			history.setPostPicture(taoBaoLink.getGoods().getPictUrl());
-
-			data.put("shareMoney", "楼" + history.getHongbao().toString());
-
+			BigDecimal shareMoney = TaoBaoUtil.getShareGoodsHongBaoInfo(taoBaoLink.getGoods(), rate);
+			
+			data.put("shareMoney", "楼" + shareMoney.toString());
+			data.put("shareId", userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId));
 			out.print(JsonUtil.loadTrueResult(data));
 
 			// 寮傛鎿嶄綔
 			com.yeshi.fanli.util.ThreadUtil.run(new Runnable() {
-
 				@Override
 				public void run() {
+					//寮傛鎿嶄綔 娣诲姞鍒嗕韩璁板綍
+					UserShareGoodsHistory history = new UserShareGoodsHistory();
+					history.setUser(new UserInfo(uid));
+					history.setHongbao(shareMoney);
+					history.setCreateTime(new Date());
+					history.setGoodsType(UserShareGoodsHistory.TYPE_TAOBAO);
+					history.setTkCode(taoBaoLink.getTaoToken());
+					history.setLink(taoBaoLink.getClickUrl());
+					history.setQuanLink(taoBaoLink.getCouponLink());
+					history.setGoodsId(taoBaoLink.getGoods().getAuctionId());
+					history.setPostPicture(taoBaoLink.getGoods().getPictUrl());
+					
+					List<String> imgList = taoBaoLink.getGoods().getImgList();
+					if (imgList == null) {
+						imgList = new ArrayList<>();
+					}
+					history.setPictures(JsonUtil.getGson().toJson(imgList));
 					shareGoodsService.addShareGoodsHistory(history);
 				}
 			});
 			return;
+		} catch (UserShareGoodsRecordException e) {
+			out.print(JsonUtil.loadFalseResult(e.getMsg()));
+			e.printStackTrace();
 		} catch (ShareGoodsException e) {
 			try {
 				monitorService.addClientAPIMonitor(MonitorFactory.createClientAPI(request, e.getCode(), 0, "鍒嗕韩鍑洪敊"));
@@ -619,7 +627,6 @@
 
 	
 
-	
 	/**
 	 * 鏌ヨ椤堕儴鍒嗙被
 	 * @param acceptData
@@ -647,29 +654,45 @@
 				return;
 			}
 			
-			JSONObject data = new JSONObject();
 			
+			
+			JSONObject data = new JSONObject();
 			// 鍒嗙被id
 			long cid = dynamicInfo.getClassId();
 			
 			if (cid == 1) { 	// 鐑攢鍗曞搧
 				// 鏂囧瓧鍐呭
-				data.put("title", JsonUtil.getApiCommonGson().toJson(dynamicInfo.getTitle()));
+				String title ="";
+				List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
+				if (listTitle != null && listTitle.size() > 0) {
+					for (ClientTextStyleVO textStyleVO : listTitle) {
+						title += textStyleVO.getContent();
+					}
+				}
+				data.put("title", title);
+				data.put("content", "鎴戝湪杩斿埄鍒稿彂鐜颁簡涓�涓緢濂界殑鍟嗗搧锛屽揩鏉ョ湅鐪媬");
+				
 				// 鍒嗕韩濂栭噾
 				ClientTextStyleVO desc = dynamicInfo.getDesc();
 				String content = desc.getContent();
 				int index = content.indexOf("楼");
 				data.put("shareMoney", new BigDecimal(content.substring(index + 1, content.length())));
+			
+				// 鍟嗗搧鍒嗕韩閾炬帴
+				List<GoodsPicture> imgs2 = dynamicInfo.getImgs();
+				GoodsPicture goodsPicture = imgs2.get(0);
+				Long auctionId = goodsPicture.getGoods().getAuctionId();
+				String url = String.format("http://%s%s?uid=%s&id=%s&appType=flq", configService.getH5Host(),
+						Constant.systemCommonConfig.getShareGoodsPagePath(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY),
+						auctionId + "");
 				
-				// 鍒嗕韩閾炬帴
-				String url = String.format("http://%s/share_mushGoods.html?uid=%s&shareId=%s&source=%s",
-						configService.getH5Host(), AESUtil.encrypt(uid + "", Constant.UIDAESKEY), id, "dynamic");
 				String shortLink = HttpUtil.getShortLink(url);
 				if (!StringUtil.isNullOrEmpty(shortLink)) {
 					url = shortLink;
 				}
 				data.put("clickUrl", url);
-				// 鍒嗕韩鏂囧瓧鍥炬爣
+				
+				// 鍒嗕韩鎻愮ず鍥剧墖
 				String imgs = configService.get("goods_share_notify_imgs");
 				JSONArray array = JSONArray.fromObject(imgs);
 				int p = (int) (array.size() * Math.random());
@@ -677,66 +700,73 @@
 					data.put("notifyPicture", array.optString(p));
 				}
 				
+				
 				UserExtraTaoBaoInfo extraInfo = userExtraTaoBaoInfoService.getByUid(uid);
 				String relationId = null;
 				if (extraInfo != null && extraInfo.getRelationId() != null && extraInfo.getRelationValid() != null
 						&& extraInfo.getRelationValid() == true) {
 					relationId = extraInfo.getRelationId();
 				}
-				TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, 42472466270L, relationId);
+				TaoBaoLink taoBaoLink = shareGoodsService.getTaoBaoLinkForShare(uid, auctionId, relationId);
 				
+				data.put("pictUrl", TbImgUtil.getTBSizeImg(goodsPicture.getUrl(), 500));
 				// 娣樺疂鍙d护
 				data.put("token", taoBaoLink.getTaoToken());
-				// 鍟嗗搧鍥剧墖閾炬帴
-				data.put("shareLink", TbImgUtil.getTBSizeImg(taoBaoLink.getGoods().getPictUrl(), 500));
 				// 甯姪閾炬帴
-				data.put("helpLink","https://img.alicdn.com/imgextra/i1/2200656425615/O1CN01dst9HQ1rLiPN7xmhD_!!0-item_pic.jpg");
+				data.put("helpLink","http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
 				// 鍒嗕韩鎻愰啋
 				data.put("notifyDesc", configService.get("goods_share_notify"));
+				// 鍒嗕韩璁板綍id
+				data.put("shareId", userShareGoodsRecordService.saveSingleShareRecord(uid, auctionId));
 				
 			} else if (cid == 2) { 	// 鎺ㄨ崘濂借揣
 				
+				String picUrl = null;
 				List<TaoBaoGoodsBrief> listGoods = new ArrayList<TaoBaoGoodsBrief>();
 				List<GoodsPicture> listImgs = dynamicInfo.getImgs();
 				for (GoodsPicture goodsPicture: listImgs) {
 					TaoBaoGoodsBriefExtra goods = goodsPicture.getGoods();
 					listGoods.add(goods);
-				}
-				
-				String title = "";
-				List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
-				for (ClientTextStyleVO textStyleVO: listTitle) {
-					title = title + textStyleVO.getContent();
-				}
-				
-				if (title.length() > 250) {
-					title = title.substring(0, 250);
+					
+					if (picUrl == null) {
+						picUrl = goodsPicture.getUrl();
+					}
 				}
 				
 				// 鏂囧瓧鍐呭
-				data.put("title", JsonUtil.getApiCommonGson().toJson(dynamicInfo.getTitle()));
+				String title ="";
+				List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
+				if (listTitle != null && listTitle.size() > 0) {
+					for (ClientTextStyleVO textStyleVO : listTitle) {
+						title += textStyleVO.getContent();
+					}
+				}
+				data.put("title", title);
+				data.put("content", "鎴戝湪杩斿埄鍒稿彂鐜颁簡涓�涓緢濂界殑鍟嗗搧锛屽揩鏉ョ湅鐪媬");
+				
 				// 鍒嗕韩濂栭噾
 				ClientTextStyleVO desc = dynamicInfo.getDesc();
 				String content = desc.getContent();
 				int index = content.indexOf("楼");
-				data.put("shareMoney", new BigDecimal(content.substring(index + 1, content.length())));
-				// 鍒嗕韩鏂囧瓧鍥炬爣
+				data.put("shareMoney", new BigDecimal(content.substring(index + 1 , content.length())));
+				
+				// 鍒嗕韩閾炬帴
+				ShareInfoDTO shareInfo = userShareGoodsRecordService.saveShareRecord(uid, 
+						ShareSourceTypeEnum.activity, title, listGoods);
+				data.put("shareId", shareInfo.getShareId());
+				data.put("clickUrl", shareInfo.getShareUrl());
+				data.put("pictUrl", TbImgUtil.getTBSizeImg(picUrl, 500));
+				// 甯姪閾炬帴
+				data.put("helpLink","http://apph5.yeshitv.com/apppage/all_help_content.html?id=148&from=singlemessage&isappinstalled=0");
+				// 鍒嗕韩鎻愰啋
+				data.put("notifyDesc", configService.get("goods_share_notify"));
+				// 鍒嗕韩鎻愰啋璇�
 				String notifyImgs = configService.get("goods_share_notify_imgs");
 				JSONArray array = JSONArray.fromObject(notifyImgs);
 				int p = (int) (array.size() * Math.random());
 				if (p < array.size()) {
 					data.put("notifyPicture", array.optString(p));
 				}
-				
-				ShareInfoDTO shareInfo = userShareGoodsRecordService.saveShareRecord(uid, ShareSourceTypeEnum.activity, title, listGoods);
-				data.put("shareId", shareInfo.getShareId());
-				data.put("clickUrl", shareInfo.getCodeUrl());
-				// 鍟嗗搧鍥剧墖閾炬帴
-				data.put("shareLink", shareInfo.getShareUrl());
-				// 甯姪閾炬帴
-				data.put("helpLink","https://img.alicdn.com/imgextra/i1/2200656425615/O1CN01dst9HQ1rLiPN7xmhD_!!0-item_pic.jpg");
-				// 鍒嗕韩鎻愰啋
-				data.put("notifyDesc", configService.get("goods_share_notify"));
 				
 			} else if (cid == 4) { // 閭�璇峰垎浜�
 				
@@ -751,18 +781,31 @@
 				
 				Integer showType = dynamicInfo.getShowType();
 				if (showType == 0) {  // 鏃犲浘鍒嗕韩
-					String shortLink = UserUtil.getInviteShortLink(uid);
+					String title ="";
 					List<ClientTextStyleVO> listTitle = dynamicInfo.getTitle();
-					for (ClientTextStyleVO textStyleVO: listTitle) {
-						String content = textStyleVO.getContent();
-						content = content.replace("閭�璇风爜", inviteCode);
-						content = content.replace("閭�璇烽摼鎺�", shortLink);
-						textStyleVO .setContent(content);
+					if (listTitle != null && listTitle.size() > 0) {
+						for (ClientTextStyleVO textStyleVO : listTitle) {
+							title += textStyleVO.getContent();
+						}
 					}
-					data.put("title", listTitle);
+					title = title.replace("銆愰個璇风爜銆�", inviteCode);
+					title = title.replace("銆愰個璇烽摼鎺ャ��", UserUtil.getInviteShortLink(uid));
+					data.put("title", title);
 					
 				} else { // 鏈夊浘鍒嗕韩
-					// 1銆侀個璇疯鍒�
+					
+					// 閭�璇烽摼鎺�
+					String shortLink = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/" 
+							+ Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
+					data.put("inviteLink", shortLink);
+					data.put("inviteCode", inviteCode);
+					
+					// 閭�璇峰浘鐗�
+					List<GoodsPicture> imgs = dynamicInfo.getImgs();
+					String imgLink = spreadUserImgService.getInviteImg(uid, imgs.get(0).getUrl(), inviteCode);
+					data.put("imgLink", imgLink);
+					
+					//  閭�璇疯鍒�
 					BusinessSystem system = new BusinessSystem();
 					system.setCreatetime(java.lang.System.currentTimeMillis());
 					system.setPlatform(1);
@@ -772,22 +815,24 @@
 					String valueN = values.getValue();
 					String valueBr = valueN.replace("\n", "<br><br>");
 					data.put("inviteRules", valueBr);
-					
-					// 閭�璇烽摼鎺�
-					String shortLink = HttpUtil.getShortLink("http://" + Constant.wxGZConfig.getLoginHost() + "/" 
-							+ Constant.systemCommonConfig.getProjectName() + "/client/threeShareNew?uid=" + uid);
-					data.put("inviteLink", shortLink);
-					
-					// 閭�璇峰浘鐗�
-					List<GoodsPicture> imgs = dynamicInfo.getImgs();
-					String imgLink = spreadUserImgService.getUserSpreadImg(uid, imgs.get(0).getUrl());
-					data.put("imgLink", imgLink);
 				}
 			}
 			out.print(JsonUtil.loadTrueResult(data));
+			
+			// 鏇存柊鍒嗕韩娆℃暟
+			executor.execute(new Runnable() {
+				@Override
+				public void run() {
+					Integer shareCount = dynamicInfo.getShareCount();
+					dynamicInfo.setShareCount(shareCount + 1);
+					dynamicInfoService.updateShareCount(dynamicInfo);
+				}
+			});
+			
 		} catch (Exception e) {
 			out.print(JsonUtil.loadFalseResult("鍒嗕韩璁板綍澶辫触"));
 			e.printStackTrace();
 		}
 	}
+	
 }

--
Gitblit v1.8.0