|
@@ -1,16 +1,26 @@
|
|
|
package com.tzld.longarticle.recommend.server.service.cgi.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.tzld.longarticle.recommend.server.common.enums.GhTypeEnum;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.cgi.ReplyStrategyServiceEnum;
|
|
|
+import com.tzld.longarticle.recommend.server.mapper.growth.GhDetailMapper;
|
|
|
import com.tzld.longarticle.recommend.server.model.cgi.BucketDataParam;
|
|
|
import com.tzld.longarticle.recommend.server.model.cgi.ReplyBucketData;
|
|
|
+import com.tzld.longarticle.recommend.server.model.param.PushMessageParam;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.model.GhDetail;
|
|
|
+import com.tzld.longarticle.recommend.server.repository.model.GhDetailExample;
|
|
|
import com.tzld.longarticle.recommend.server.service.cgi.CgiReplyService;
|
|
|
import com.tzld.longarticle.recommend.server.service.strategy.reply.ReplyStrategyService;
|
|
|
+import com.tzld.longarticle.recommend.server.util.LarkRobotUtil;
|
|
|
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.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class CgiReplyServiceImpl implements CgiReplyService {
|
|
@@ -20,23 +30,52 @@ public class CgiReplyServiceImpl implements CgiReplyService {
|
|
|
|
|
|
private Map<String, ReplyStrategyService> strategyServiceMap;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private GhDetailMapper ghDetailMapper;
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
strategyServiceMap = applicationContext.getBeansOfType(ReplyStrategyService.class);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 当前使用策略
|
|
|
- */
|
|
|
- private final ReplyStrategyServiceEnum useStrategy = ReplyStrategyServiceEnum.BUCKET_STRATEGY_V1;
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public ReplyBucketData getRgiReplyData(BucketDataParam bucketDataParam) {
|
|
|
+ String ghId = bucketDataParam.getGhId();
|
|
|
+ GhDetailExample example = new GhDetailExample();
|
|
|
+ example.createCriteria().andGhIdEqualTo(ghId);
|
|
|
+ List<GhDetail> ghDetails = ghDetailMapper.selectByExample(example);
|
|
|
+ if (CollectionUtils.isEmpty(ghDetails)) {
|
|
|
+ LarkRobotUtil.sendMessage("公众号信息查询失败 ghId=" + ghId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ GhDetail ghDetail = ghDetails.get(0);
|
|
|
+ if (Objects.equals(ghDetail.getType(), GhTypeEnum.THIRD_PARTY_GH.type)) {
|
|
|
+ bucketDataParam.setChannel(ghDetail.getChannel());
|
|
|
+ return getPushMessageData(bucketDataParam);
|
|
|
+ }
|
|
|
+ return getRgiBucketData(bucketDataParam);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ReplyBucketData getRgiBucketData(BucketDataParam bucketDataParam) {
|
|
|
+ for (Map.Entry<String, ReplyStrategyService> stringReplyStrategyServiceEntry : strategyServiceMap.entrySet()) {
|
|
|
+ ReplyStrategyService replyStrategyService = stringReplyStrategyServiceEntry.getValue();
|
|
|
+ // 使用策略层
|
|
|
+ if (replyStrategyService.support(ReplyStrategyServiceEnum.BUCKET_STRATEGY_V1)) {
|
|
|
+ return replyStrategyService.getResult(bucketDataParam);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 无执行策略 不会走到这里
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ReplyBucketData getPushMessageData(BucketDataParam bucketDataParam) {
|
|
|
for (Map.Entry<String, ReplyStrategyService> stringReplyStrategyServiceEntry : strategyServiceMap.entrySet()) {
|
|
|
ReplyStrategyService replyStrategyService = stringReplyStrategyServiceEntry.getValue();
|
|
|
// 使用策略层
|
|
|
- if (replyStrategyService.support(useStrategy)) {
|
|
|
+ if (replyStrategyService.support(ReplyStrategyServiceEnum.PUSH_MESSAGE_STRATEGY_V1)) {
|
|
|
+ bucketDataParam.setGhId(bucketDataParam.getGhId());
|
|
|
+ bucketDataParam.setChannel(bucketDataParam.getChannel());
|
|
|
return replyStrategyService.getResult(bucketDataParam);
|
|
|
}
|
|
|
}
|