| 
					
				 | 
			
			
				@@ -0,0 +1,83 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package com.tzld.longarticle.recommend.server.service.exterior.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.common.response.CommonResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.bo.MiniData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.cgi.BucketDataParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.cgi.GroupData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.cgi.MsgData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.cgi.ReplyBucketData; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.param.PushMessageParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.param.WeComPushMessageParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.vo.PushMessageVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.model.vo.WeComPushMessageVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.service.exterior.WeComService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.tzld.longarticle.recommend.server.service.strategy.reply.ReplyStrategyService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import lombok.extern.slf4j.Slf4j; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.BeanUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.context.ApplicationContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.springframework.util.CollectionUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import javax.annotation.PostConstruct; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.ArrayList; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Slf4j 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+public class WeComServiceImpl implements WeComService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ApplicationContext applicationContext; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private Map<String, ReplyStrategyService> strategyServiceMap; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @PostConstruct 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public void init() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        strategyServiceMap = applicationContext.getBeansOfType(ReplyStrategyService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public CommonResponse<List<WeComPushMessageVo>> getPushMessage(WeComPushMessageParam param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<WeComPushMessageVo> res = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ReplyBucketData replyBucketData = getPushMessageData(param); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        List<GroupData> groupList = replyBucketData.getGroupList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if(CollectionUtils.isEmpty(groupList)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return CommonResponse.create(500,"数据异常"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (GroupData groupData : groupList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (CollectionUtils.isEmpty(groupData.getMsgDataList())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            WeComPushMessageVo weComPushMessageVo = new WeComPushMessageVo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            weComPushMessageVo.setGroupIndex(groupData.getGroupIndex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            List<MsgData> msgDataList = groupData.getMsgDataList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            MsgData msgData = new MsgData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            msgData.setMsgType(3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            msgData.setTitle("欢迎你的到来"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            msgDataList.add(0, msgData); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            weComPushMessageVo.setMsgDataList(msgDataList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            res.add(weComPushMessageVo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return CommonResponse.success(res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private ReplyBucketData getPushMessageData(WeComPushMessageParam param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("strategyServiceMap={}", JSON.toJSONString(strategyServiceMap)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        for (Map.Entry<String, ReplyStrategyService> stringReplyStrategyServiceEntry : strategyServiceMap.entrySet()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ReplyStrategyService replyStrategyService = stringReplyStrategyServiceEntry.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 使用策略层 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (replyStrategyService.support(ReplyStrategyServiceEnum.BUCKET_STRATEGY_V1)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                BucketDataParam bucketDataParam = new BucketDataParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                bucketDataParam.setGhId(param.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                return replyStrategyService.getResult(bucketDataParam); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 无执行策略 不会走到这里 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |