From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期六, 18 一月 2020 12:06:27 +0800
Subject: [PATCH] 用户注册信息

---
 fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java |  271 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 203 insertions(+), 68 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java b/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java
index 4bd3795..0619fa1 100644
--- a/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java
+++ b/fanli/src/main/java/com/yeshi/fanli/job/DynamicInfoJob.java
@@ -1,5 +1,7 @@
 package com.yeshi.fanli.job;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
@@ -9,32 +11,66 @@
 import org.springframework.stereotype.Component;
 import org.yeshi.utils.DateUtil;
 
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import com.yeshi.fanli.dto.ConfigParamsDTO;
 import com.yeshi.fanli.entity.bus.activity.RecommendActivity;
+import com.yeshi.fanli.entity.bus.activity.RecommendActivityInviteInfo;
+import com.yeshi.fanli.entity.dynamic.GoodsPicture;
+import com.yeshi.fanli.entity.dynamic.WXMPDynamicInfo;
+import com.yeshi.fanli.entity.goods.jd.NYouHuiGoods;
+import com.yeshi.fanli.entity.jd.JDGoods;
 import com.yeshi.fanli.log.LogHelper;
 import com.yeshi.fanli.service.inter.activity.ActivityService;
+import com.yeshi.fanli.service.inter.activity.ActivityUserService;
+import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
 import com.yeshi.fanli.service.inter.dynamic.DynamicInfoService;
+import com.yeshi.fanli.service.inter.dynamic.WXMPDynamicInfoService;
+import com.yeshi.fanli.service.inter.goods.jd.NYouHuiService;
+import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
+import com.yeshi.fanli.service.manger.goods.ConvertLinkManager;
 import com.yeshi.fanli.util.Constant;
+import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
+import com.yeshi.fanli.util.jd.JDApiUtil;
+import com.yeshi.fanli.util.jd.JDUtil;
 
 @Component
 public class DynamicInfoJob {
-	
+
 	@Resource
 	private DynamicInfoService dynamicInfoService;
-	
+
 	@Resource
 	private ActivityService activityService;
-	
-	
+
+	@Resource
+	private NYouHuiService nyouHuiService;
+
+	@Resource
+	private ActivityUserService activityUserService;
+
+	@Resource
+	private WXMPDynamicInfoService wxmpDynamicInfoService;
+
+	@Resource
+	private ConvertLinkManager convertLinkManager;
+
+	@Resource
+	private HongBaoManageService hongBaoManageService;
+
+	@Resource
+	private JumpDetailV2Service jumpDetailV2Service;
+
 	/**
 	 * 姣�10鍒嗛挓  鏅氫笂00:00~06:00涓嶄笅鍙戜换浣曚竴涓晢鍝�
 	 */
 	@Scheduled(cron = "0 0/10 6-23 * * ?")
 	public void insetDynamicInfo() {
-		
-//		if (!Constant.IS_TASK) {
-//			return;
-//		}
-		
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
 		try {
 			dynamicInfoService.insertTimeHotSale();
 		} catch (Exception e) {
@@ -44,8 +80,7 @@
 				e1.printStackTrace();
 			}
 		}
-		
-		
+
 		try {
 			dynamicInfoService.insertTimeRecommend();
 		} catch (Exception e) {
@@ -56,18 +91,17 @@
 			}
 		}
 	}
-	
-	
+
 	/**
 	 * 鏃╀笂6,7,15,16,21,22,23鐐规洿鏂�1娆�
 	 */
 	@Scheduled(cron = "0 0 6,7,15,16,21,22,23 * * ? ")
 	public void insetShopInfo1() {
-		
-//		if (!Constant.IS_TASK) {
-//			return;
-//		}
-		
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
 		try {
 			dynamicInfoService.insertShopInfo();
 		} catch (Exception e) {
@@ -78,17 +112,17 @@
 			}
 		}
 	}
-	
+
 	/**
 	 * 鏃╀笂8:00~10:00姣忓崐涓皬鏃舵洿鏂�
 	 */
 	@Scheduled(cron = "0 0/30 8,9,10 * * ?")
 	public void insetShopInfo2() {
-		
-//		if (!Constant.IS_TASK) {
-//			return;
-//		}
-		
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
 		try {
 			dynamicInfoService.insertShopInfo();
 		} catch (Exception e) {
@@ -99,18 +133,17 @@
 			}
 		}
 	}
-	
-	
+
 	/**
 	 * 鏃╀笂11:00~14:00姣忓崐涓皬鏃舵洿鏂�
 	 */
 	@Scheduled(cron = "0 0/30 11,12,13,14 * * ?")
 	public void insetShopInfo3() {
-		
-//		if (!Constant.IS_TASK) {
-//			return;
-//		}
-		
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
 		try {
 			dynamicInfoService.insertShopInfo();
 		} catch (Exception e) {
@@ -121,18 +154,17 @@
 			}
 		}
 	}
-	
-	
+
 	/**
 	 * 涓嬪崍17:00~20:00姣忓崐涓皬鏃舵洿鏂�
 	 */
 	@Scheduled(cron = "0 0/30 17,18,19,20 * * ? ")
 	public void insetShopInfo4() {
-		
+
 		if (!Constant.IS_TASK) {
 			return;
 		}
-		
+
 		try {
 			dynamicInfoService.insertShopInfo();
 		} catch (Exception e) {
@@ -142,21 +174,21 @@
 				e1.printStackTrace();
 			}
 		}
-	}	
-	
-	
+	}
+
 	/**
 	 * 姣忓ぉ闆剁偣鍒犻櫎3澶╀箣鍓嶆暟鎹�
 	 */
-	@Scheduled(cron = "0 0 0 * * ?")
+	@Scheduled(cron = "0 0 1,10 * * ?")
 	public void remove() {
-		
-//		if (!Constant.IS_TASK) {
-//			return;
-//		}
-		
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
 		try {
-			dynamicInfoService.removeByDate(DateUtil.reduceDay(3, new Date()));
+			LogHelper.test("DynamicInfoJob-remove-寮�濮嬫墽琛屾��");
+			dynamicInfoService.removeByDate(DateUtil.reduceDay(2, new Date()));
 		} catch (Exception e) {
 			try {
 				LogHelper.errorDetailInfo(e);
@@ -165,49 +197,45 @@
 			}
 		}
 	}
-	
-	
+
 	/**
 	 *  鍚庡彴缂栬緫鍔ㄦ�侊細 姣�3鍒嗛挓妫�绱�
 	 */
 	@Scheduled(cron = "0 0/3 * * * ?")
 	public void activityNeedPublish() {
-		
-//		if (!Constant.IS_TASK) {
-//			return;
-//		}
-		
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
 		try {
 			List<RecommendActivity> list = activityService.getNeedPublish();
 			if (list == null || list.size() == 0) {
 				return;
 			}
-			
-			
+
 			for (RecommendActivity activity : list) {
 				Integer type = activity.getType();
 				if (RecommendActivity.TYPE_SHARE_GOODS == type) {
 					// 鍟嗗搧鍔ㄦ��
-					dynamicInfoService.saveActivityRecommend(activity);
-					
+					dynamicInfoService.insertActivityRecommend(activity);
+
 					activity.setState(1);
 					activityService.updateByPrimaryKeySelective(activity);
-					
+
 				} else if (RecommendActivity.TYPE_INVITE == type) {
 					// 閭�璇风礌鏉�
-					String imgUrl = null;
-					List<String> imageList = activityService.getImgByActivityId(activity.getId());
-					if (imageList != null && imageList.size() > 0) {
-						imgUrl = imageList.get(0);
-					}
-					
-					dynamicInfoService.insertInviteMaterial(activity.getTitle(), imgUrl, activity.getId(), activity.getActivityUser());
-					
+					RecommendActivityInviteInfo inviteInfo = activityService
+							.getRecommendActivityInviteInfoByActivityId(activity.getId());
+					activity.setInviteInfo(inviteInfo);
+
+					dynamicInfoService.insertInviteActivity(activity);
+
 					activity.setState(1);
 					activityService.updateByPrimaryKeySelective(activity);
 				}
 			}
-			
+
 		} catch (Exception e) {
 			try {
 				LogHelper.errorDetailInfo(e);
@@ -216,6 +244,113 @@
 			}
 		}
 	}
-	
-	
+
+	/**
+	 * 姣忓ぉ6鐐瑰ぉ鏇存柊閭�璇风礌鏉�
+	 */
+	@Scheduled(cron = "0 0 6 * * ?")
+	public void insertTimeInvite() {
+
+		if (!Constant.IS_TASK) {
+			return;
+		}
+
+		try {
+			dynamicInfoService.insertTimeInvite();
+		} catch (Exception e) {
+			try {
+				LogHelper.errorDetailInfo(e);
+			} catch (Exception e1) {
+				e1.printStackTrace();
+			}
+		}
+	}
+
+	/**
+	 * 
+	 * @Title: demoJobHandler
+	 * @Description: 鏇存柊灏忕▼搴忓姩鎬佸晢鍝�
+	 * @param param
+	 * @return
+	 * @throws Exception 
+	 * ReturnT<String> 杩斿洖绫诲瀷
+	 * @throws
+	 */
+	@XxlJob("dynamic-updateWXMPDynamicInfo")
+	public ReturnT<String> updateWXMPDynamicInfoHandler(String param) throws Exception {
+		addJDNYHInfo();
+		return ReturnT.SUCCESS;
+	}
+
+	/**
+	 * 娣诲姞鍐呬紭鎯犵浉鍏冲晢鍝�
+	 * @Title: addJDNYHInfo
+	 * @Description:  
+	 * void 杩斿洖绫诲瀷
+	 * @throws
+	 */
+	private void addJDNYHInfo() throws Exception {
+
+		List<NYouHuiGoods> list = nyouHuiService.list(1, 1);
+		if (list != null && list.size() > 0) {
+			NYouHuiGoods goods = list.get(0);
+			String id = goods.toId();
+			WXMPDynamicInfo info = new WXMPDynamicInfo();
+			info.setId(WXMPDynamicInfo.SOURCE_NYH + "#" + id);
+			String desc = goods.getDesc();
+
+			info.setSource(WXMPDynamicInfo.SOURCE_NYH);
+			info.setUser(activityUserService.getRandomHaoHuo());
+			// 鍋氶摼鎺ヨ浆鎹�
+			for (String link : goods.getLinkList()) {
+				desc = desc.replaceFirst("\\[閾炬帴\\]", link);
+			}
+
+			desc = convertLinkManager.convertJDLinkFromText(desc, 0L, true);
+			info.setContent(desc);
+
+			List<JDGoods> goodsList = JDApiUtil.queryGoodsDetail(goods.getSkuList());
+			List<GoodsPicture> imgs = new ArrayList<>();
+
+			BigDecimal totalMoney = new BigDecimal(0);
+			List<String> lastPicture = new ArrayList<>();
+			for (JDGoods jdGoods : goodsList) {
+				GoodsPicture picture = new GoodsPicture();
+				BigDecimal money = JDUtil.getGoodsFanLiMoney(jdGoods, hongBaoManageService.getShareRate());
+				totalMoney = totalMoney.add(money);
+				picture.setGoodsVO(
+						GoodsDetailVOFactory.convertJDGoods(jdGoods,
+								new ConfigParamsDTO(hongBaoManageService.getFanLiRate(),
+										hongBaoManageService.getShareRate(), null,
+										hongBaoManageService.getVIPFanLiRate())));
+				picture.setGoodState(0);
+				picture.setJumpDetail(jumpDetailV2Service.getByTypeCache("goodsdetail"));
+				picture.setParams(null);
+				picture.setUrl(jdGoods.getPicUrl());
+				imgs.add(picture);
+				if (jdGoods.getImageList() != null)
+					if (jdGoods.getImageList().size() > 4)
+						lastPicture.addAll(jdGoods.getImageList().subList(1, 4));
+					else if (jdGoods.getImageList().size() > 1)
+						lastPicture.addAll(jdGoods.getImageList().subList(1, jdGoods.getImageList().size()));
+			}
+			info.setShareMoney(totalMoney);
+			int count = 0;
+			while (imgs.size() < 4 && count < 4) {
+				count++;
+				String picurl = lastPicture.get((int) (lastPicture.size() * Math.random()));
+				if (picurl != null) {
+					lastPicture.remove(picurl);
+					GoodsPicture picture = new GoodsPicture();
+					picture.setUrl(picurl);
+					imgs.add(picture);
+				}
+			}
+
+			info.setImgs(imgs);
+
+			wxmpDynamicInfoService.addWXMPDynamicInfo(info);
+		}
+	}
+
 }

--
Gitblit v1.8.0