Jelajahi Sumber

企微自动回复增加保底

xueyiming 3 bulan lalu
induk
melakukan
b82ddeb0eb

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/common/enums/SecretEnum.java

@@ -9,7 +9,7 @@ public enum SecretEnum {
     SECRET_ENUM_1("3b83574b477d4c5b8508a6e33f6e35ec", "魅力", "ml"),
     SECRET_ENUM_2("70d342bf11a84ac7aca6b3e99541e085", "老来福", "llf"),
     SECRET_ENUM_3("595db67618174499b2bed23d8be6a3c1", "微小盟", "wxm"),
-    SECRET_ENUM_4("9a48498757774ddf8a3878b9c02d0fef", "福州像素", "xs"),
+    SECRET_ENUM_4("9a48498757774ddf8a3878b9c02d0fef", "像素", "xs"),
     SECRET_ENUM_5("35afea64fd374477bb32999120b91637", "泽火", "zh"),
     SECRET_ENUM_6("ee93a44c4be4448ab0ac9334a296016e", "云誉", "yy"),
     SECRET_ENUM_7("da2c526d31d14430b49af808e90542dc", "创易", "cy"),

+ 31 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/generator/ApiMybatisGeneratorMain.java

@@ -0,0 +1,31 @@
+package com.tzld.piaoquan.api.dao.generator;
+
+import org.mybatis.generator.api.MyBatisGenerator;
+import org.mybatis.generator.config.Configuration;
+import org.mybatis.generator.config.xml.ConfigurationParser;
+import org.mybatis.generator.exception.InvalidConfigurationException;
+import org.mybatis.generator.exception.XMLParserException;
+import org.mybatis.generator.internal.DefaultShellCallback;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class ApiMybatisGeneratorMain {
+
+    public static void main(String[] args)
+            throws SQLException, IOException, InterruptedException, InvalidConfigurationException, XMLParserException {
+        List<String> warnings = new ArrayList<>();
+
+        File configFile = new File(ApiMybatisGeneratorMain.class.getResource("/mybatis-api-generator-config.xml").getFile());
+        ConfigurationParser cp = new ConfigurationParser(warnings);
+        Configuration config = cp.parseConfiguration(configFile);
+        DefaultShellCallback callback = new DefaultShellCallback(true);
+        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
+        myBatisGenerator.generate(null);
+        System.out.println("genreate finish");
+    }
+}

+ 7 - 13
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/ReplyStaffMapper.java

@@ -1,16 +1,10 @@
 package com.tzld.piaoquan.api.dao.mapper;
 
-
 import com.tzld.piaoquan.api.model.po.ReplyStaff;
 import com.tzld.piaoquan.api.model.po.ReplyStaffExample;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-import org.springframework.stereotype.Repository;
-
 import java.util.List;
+import org.apache.ibatis.annotations.Param;
 
-@Mapper
-@Repository
 public interface ReplyStaffMapper {
     long countByExample(ReplyStaffExample example);
 
@@ -18,19 +12,19 @@ public interface ReplyStaffMapper {
 
     int deleteByPrimaryKey(Long id);
 
-    int insert(ReplyStaff row);
+    int insert(ReplyStaff record);
 
-    int insertSelective(ReplyStaff row);
+    int insertSelective(ReplyStaff record);
 
     List<ReplyStaff> selectByExample(ReplyStaffExample example);
 
     ReplyStaff selectByPrimaryKey(Long id);
 
-    int updateByExampleSelective(@Param("row") ReplyStaff row, @Param("example") ReplyStaffExample example);
+    int updateByExampleSelective(@Param("record") ReplyStaff record, @Param("example") ReplyStaffExample example);
 
-    int updateByExample(@Param("row") ReplyStaff row, @Param("example") ReplyStaffExample example);
+    int updateByExample(@Param("record") ReplyStaff record, @Param("example") ReplyStaffExample example);
 
-    int updateByPrimaryKeySelective(ReplyStaff row);
+    int updateByPrimaryKeySelective(ReplyStaff record);
 
-    int updateByPrimaryKey(ReplyStaff row);
+    int updateByPrimaryKey(ReplyStaff record);
 }

+ 29 - 2
api-module/src/main/java/com/tzld/piaoquan/api/model/po/ReplyStaff.java

@@ -9,6 +9,8 @@ public class ReplyStaff {
 
     private String name;
 
+    private String videoIds;
+
     private Integer isDelete;
 
     private Date createTime;
@@ -28,7 +30,7 @@ public class ReplyStaff {
     }
 
     public void setUserId(String userId) {
-        this.userId = userId == null ? null : userId.trim();
+        this.userId = userId;
     }
 
     public String getName() {
@@ -36,7 +38,15 @@ public class ReplyStaff {
     }
 
     public void setName(String name) {
-        this.name = name == null ? null : name.trim();
+        this.name = name;
+    }
+
+    public String getVideoIds() {
+        return videoIds;
+    }
+
+    public void setVideoIds(String videoIds) {
+        this.videoIds = videoIds;
     }
 
     public Integer getIsDelete() {
@@ -62,4 +72,21 @@ public class ReplyStaff {
     public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
     }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", id=").append(id);
+        sb.append(", userId=").append(userId);
+        sb.append(", name=").append(name);
+        sb.append(", videoIds=").append(videoIds);
+        sb.append(", isDelete=").append(isDelete);
+        sb.append(", createTime=").append(createTime);
+        sb.append(", updateTime=").append(updateTime);
+        sb.append("]");
+        return sb.toString();
+    }
 }

+ 99 - 16
api-module/src/main/java/com/tzld/piaoquan/api/model/po/ReplyStaffExample.java

@@ -1,5 +1,7 @@
 package com.tzld.piaoquan.api.model.po;
 
+import com.tzld.piaoquan.growth.common.utils.page.Page;
+
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -11,8 +13,10 @@ public class ReplyStaffExample {
 
     protected List<Criteria> oredCriteria;
 
+    protected Page page;
+
     public ReplyStaffExample() {
-        oredCriteria = new ArrayList<>();
+        oredCriteria = new ArrayList<Criteria>();
     }
 
     public void setOrderByClause(String orderByClause) {
@@ -64,12 +68,20 @@ public class ReplyStaffExample {
         distinct = false;
     }
 
+    public void setPage(Page page) {
+        this.page=page;
+    }
+
+    public Page getPage() {
+        return page;
+    }
+
     protected abstract static class GeneratedCriteria {
         protected List<Criterion> criteria;
 
         protected GeneratedCriteria() {
             super();
-            criteria = new ArrayList<>();
+            criteria = new ArrayList<Criterion>();
         }
 
         public boolean isValid() {
@@ -236,72 +248,142 @@ public class ReplyStaffExample {
         }
 
         public Criteria andNameIsNull() {
-            addCriterion("name is null");
+            addCriterion("`name` is null");
             return (Criteria) this;
         }
 
         public Criteria andNameIsNotNull() {
-            addCriterion("name is not null");
+            addCriterion("`name` is not null");
             return (Criteria) this;
         }
 
         public Criteria andNameEqualTo(String value) {
-            addCriterion("name =", value, "name");
+            addCriterion("`name` =", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameNotEqualTo(String value) {
-            addCriterion("name <>", value, "name");
+            addCriterion("`name` <>", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameGreaterThan(String value) {
-            addCriterion("name >", value, "name");
+            addCriterion("`name` >", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameGreaterThanOrEqualTo(String value) {
-            addCriterion("name >=", value, "name");
+            addCriterion("`name` >=", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameLessThan(String value) {
-            addCriterion("name <", value, "name");
+            addCriterion("`name` <", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameLessThanOrEqualTo(String value) {
-            addCriterion("name <=", value, "name");
+            addCriterion("`name` <=", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameLike(String value) {
-            addCriterion("name like", value, "name");
+            addCriterion("`name` like", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameNotLike(String value) {
-            addCriterion("name not like", value, "name");
+            addCriterion("`name` not like", value, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameIn(List<String> values) {
-            addCriterion("name in", values, "name");
+            addCriterion("`name` in", values, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameNotIn(List<String> values) {
-            addCriterion("name not in", values, "name");
+            addCriterion("`name` not in", values, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameBetween(String value1, String value2) {
-            addCriterion("name between", value1, value2, "name");
+            addCriterion("`name` between", value1, value2, "name");
             return (Criteria) this;
         }
 
         public Criteria andNameNotBetween(String value1, String value2) {
-            addCriterion("name not between", value1, value2, "name");
+            addCriterion("`name` not between", value1, value2, "name");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsIsNull() {
+            addCriterion("video_ids is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsIsNotNull() {
+            addCriterion("video_ids is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsEqualTo(String value) {
+            addCriterion("video_ids =", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsNotEqualTo(String value) {
+            addCriterion("video_ids <>", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsGreaterThan(String value) {
+            addCriterion("video_ids >", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsGreaterThanOrEqualTo(String value) {
+            addCriterion("video_ids >=", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsLessThan(String value) {
+            addCriterion("video_ids <", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsLessThanOrEqualTo(String value) {
+            addCriterion("video_ids <=", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsLike(String value) {
+            addCriterion("video_ids like", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsNotLike(String value) {
+            addCriterion("video_ids not like", value, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsIn(List<String> values) {
+            addCriterion("video_ids in", values, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsNotIn(List<String> values) {
+            addCriterion("video_ids not in", values, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsBetween(String value1, String value2) {
+            addCriterion("video_ids between", value1, value2, "videoIds");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdsNotBetween(String value1, String value2) {
+            addCriterion("video_ids not between", value1, value2, "videoIds");
             return (Criteria) this;
         }
 
@@ -487,6 +569,7 @@ public class ReplyStaffExample {
     }
 
     public static class Criteria extends GeneratedCriteria {
+
         protected Criteria() {
             super();
         }

+ 3 - 3
api-module/src/main/java/com/tzld/piaoquan/api/service/impl/ThirdPartyServiceImpl.java

@@ -156,13 +156,13 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
         long nowTimestamp = System.currentTimeMillis() / 1000;
         long limitTime = nowTimestamp - 34L * TimeConstant.HOUR;
         long targetTime = DateUtil.dateStrToTimestamp(date, "yyyy-MM-dd");
-        String channel = secretEnum.channel;
+        String desc = secretEnum.desc;
         if (targetTime > limitTime) {
             return CommonResponse.create(500, "数据不存在");
         }
         String dt = date.replace("-", "").substring(0, 8);
-        String sql = String.format("SELECT * FROM alg_growth_3rd_gh_reply_uv_report WHERE dt = %s AND channel = '%s';",
-                dt, channel);
+        String sql = String.format("SELECT * FROM gzh_autoreply_behavior_uv_total WHERE dt = %s AND 合作方 = '%s';",
+                dt, desc);
         List<ReportUvVo> res = new ArrayList<>();
         List<Record> recordList = odpsManager.query(sql);
         if (CollectionUtils.isEmpty(recordList)) {

+ 16 - 9
api-module/src/main/java/com/tzld/piaoquan/api/service/impl/WeComServiceImpl.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.api.service.impl;
 
 import com.alibaba.fastjson.JSON;
 
+import com.alibaba.fastjson.JSONArray;
 import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
 import com.tzld.piaoquan.api.dao.mapper.ReplyStaffMapper;
 import com.tzld.piaoquan.api.model.bo.BucketDataParam;
@@ -16,6 +17,7 @@ import com.tzld.piaoquan.api.service.WeComService;
 import com.tzld.piaoquan.api.service.strategy.ReplyStrategyService;
 import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
 import com.tzld.piaoquan.growth.common.common.enums.ExceptionCodeEnum;
+import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -56,8 +58,16 @@ public class WeComServiceImpl implements WeComService {
         if (param == null || StringUtils.isEmpty(param.getCorpId()) || !CORP_ID.equals(param.getCorpId()) || StringUtils.isEmpty(param.getUserId())) {
             return CommonResponse.create(ExceptionCodeEnum.PARAMS_ERROR, "参数错误");
         }
+
+        ReplyStaffExample example = new ReplyStaffExample();
+        example.createCriteria().andUserIdEqualTo(param.getUserId()).andIsDeleteEqualTo(0);
+        List<ReplyStaff> replyStaffs = replyStaffMapper.selectByExample(example);
+        if (CollectionUtils.isEmpty(replyStaffs)) {
+            return CommonResponse.create(ExceptionCodeEnum.PARAMS_ERROR, "用户查询不到");
+        }
+        ReplyStaff replyStaff = replyStaffs.get(0);
         List<WeComPushMessageVo> res = new ArrayList<>();
-        ReplyBucketData replyBucketData = getPushMessageData(param);
+        ReplyBucketData replyBucketData = getPushMessageData(param, replyStaff.getVideoIds());
         if (replyBucketData == null) {
             return CommonResponse.create(500, "数据异常");
         }
@@ -66,13 +76,6 @@ public class WeComServiceImpl implements WeComService {
         if (CollectionUtils.isEmpty(groupList)) {
             return CommonResponse.create(500, "数据异常");
         }
-        ReplyStaffExample example = new ReplyStaffExample();
-        example.createCriteria().andUserIdEqualTo(param.getUserId()).andIsDeleteEqualTo(0);
-        List<ReplyStaff> replyStaffs = replyStaffMapper.selectByExample(example);
-        if (CollectionUtils.isEmpty(replyStaffs)) {
-            return CommonResponse.create(ExceptionCodeEnum.PARAMS_ERROR, "用户查询不到");
-        }
-        ReplyStaff replyStaff = replyStaffs.get(0);
         String name = replyStaff.getName();
         for (GroupData groupData : groupList) {
             if (CollectionUtils.isEmpty(groupData.getMsgDataList())) {
@@ -105,7 +108,7 @@ public class WeComServiceImpl implements WeComService {
         return CommonResponse.success(res);
     }
 
-    private ReplyBucketData getPushMessageData(WeComPushMessageParam param) {
+    private ReplyBucketData getPushMessageData(WeComPushMessageParam param, String videoIds) {
         log.info("strategyServiceMap={}", JSON.toJSONString(strategyServiceMap));
         for (Map.Entry<String, ReplyStrategyService> stringReplyStrategyServiceEntry : strategyServiceMap.entrySet()) {
             ReplyStrategyService replyStrategyService = stringReplyStrategyServiceEntry.getValue();
@@ -113,6 +116,10 @@ public class WeComServiceImpl implements WeComService {
             if (replyStrategyService.support(ReplyStrategyServiceEnum.WE_COM_PUSH_MESSAGE_STRATEGY_V1)) {
                 BucketDataParam bucketDataParam = new BucketDataParam();
                 bucketDataParam.setGhId(param.getUserId());
+                if (StringUtils.isNotEmpty(videoIds)) {
+                    bucketDataParam.setStrategyStatus(StrategyStatusEnum.DEFAULT.status);
+                    bucketDataParam.setVideos(JSONArray.parseArray(videoIds, Long.class));
+                }
                 return replyStrategyService.getResult(bucketDataParam);
             }
         }

+ 76 - 37
api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/WeComPushMessageStrategyV1.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
 import com.tzld.piaoquan.api.component.TouLiuHttpClient;
 import com.tzld.piaoquan.api.dao.mapper.AlgGhAutoreplyVideoRankDataMapper;
+import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
 import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
 import com.tzld.piaoquan.api.model.bo.*;
 import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankData;
@@ -39,6 +40,8 @@ public class WeComPushMessageStrategyV1 implements ReplyStrategyService {
      */
     private static final String bucketStrategyConfig = "{\"we-com-base\":[0,1,2,3,4,5,6],\"we-com-explore1\":[7],\"we-com-explore2\":[8,9]}";
 
+
+    private static final String manualConfig = "{\"we-com-manual\":[0,1,2,3,4,5,6,7,8,9]}";
     /**
      * 自动回复使用小程序Id
      */
@@ -60,8 +63,13 @@ public class WeComPushMessageStrategyV1 implements ReplyStrategyService {
     public ReplyBucketData getResult(BucketDataParam bucketDataParam) {
         log.info("ThirdPartyPushMessageStrategyV1 start");
         // 0 获取策略key
-        JSONObject bucketStrategyConfigJsonObject = JSON.parseObject(bucketStrategyConfig);
-        Set<String> keyedSet = bucketStrategyConfigJsonObject.keySet();
+        JSONObject configJsonObject;
+        if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
+            configJsonObject = JSON.parseObject(manualConfig);
+        } else {
+            configJsonObject = JSON.parseObject(bucketStrategyConfig);
+        }
+        Set<String> keyedSet = configJsonObject.keySet();
         // 1 处理文章--算法引擎--排序文章数据
 //        getWenzhangData();
         // 2 处理小程序--读取离线数据表--获取策略排序小程序数据
@@ -72,7 +80,7 @@ public class WeComPushMessageStrategyV1 implements ReplyStrategyService {
         // 3 入库读表
         insertSmallData(smallDataCgiReplyList, keyedSet, bucketDataParam);
         // 4 组装分桶数据
-        return getReplyBucketData(bucketStrategyConfigJsonObject, keyedSet, bucketDataParam.getGhId());
+        return getReplyBucketData(configJsonObject, keyedSet, bucketDataParam.getGhId());
     }
 
     private ReplyBucketData getReplyBucketData(JSONObject bucketStrategyConfigJsonObject, Set<String> keyedSet, String ghId) {
@@ -207,41 +215,72 @@ public class WeComPushMessageStrategyV1 implements ReplyStrategyService {
                 // base作为人工控制
                 continue;
             }
-            // 获取最新dt的策略
-            String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
-            if (StringUtils.isEmpty(dtVersion)) {
-                continue;
-            }
-            // 判断当前的dtVersion是否已经处理过了
-            CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
-            cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyDtEqualTo(dtVersion).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
-            long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
-            if (count != 0) {
-                // 说明已处理过该dtVersion数据
-                continue;
-            }
-            // 获取最新dt数据
-            List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
-            List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
-            Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(videoIds);
-            result.addAll(dtVersionStrategyData.stream().map(x -> {
-                CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
-                cgiReplyBucketData.setStrategy(key);
-                cgiReplyBucketData.setSort(x.getSort());
-                cgiReplyBucketData.setStrategyDt(x.getDtVersion());
-                cgiReplyBucketData.setGhId(x.getGhId());
-                cgiReplyBucketData.setMsgType(1);
-                cgiReplyBucketData.setTitle(x.getTitle());
-                VideoDetail videoDetail = videoDetailMap.get(x.getVideoId());
-                if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
-                    cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
-                } else {
-                    cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
+            if (Objects.equals(StrategyStatusEnum.DEFAULT.status, bucketDataParam.getStrategyStatus())) {
+                if (CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
+                    return null;
                 }
-                cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
-                cgiReplyBucketData.setMiniVideoId(x.getVideoId());
-                return cgiReplyBucketData;
-            }).collect(Collectors.toList()));
+                CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
+                        .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniVideoIdIn(bucketDataParam.getVideos());
+                long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                if (count == bucketDataParam.getVideos().size()) {
+                    // 已经存在就不处理
+                    continue;
+                }
+                Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
+                int sort = 1;
+                for (Long videoId : bucketDataParam.getVideos()) {
+                    CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                    cgiReplyBucketData.setStrategy(key);
+                    cgiReplyBucketData.setSort(sort);
+                    cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
+                    cgiReplyBucketData.setMsgType(1);
+                    VideoDetail videoDetail = videoDetailMap.get(videoId);
+                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                        cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
+                    }
+                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
+                        cgiReplyBucketData.setTitle(videoDetail.getTitle());
+                    }
+                    cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                    cgiReplyBucketData.setMiniVideoId(videoId);
+                    result.add(cgiReplyBucketData);
+                    sort++;
+                }
+            } else {
+                // 获取最新dt的策略
+                String dtVersion = algGhAutoreplyVideoRankDataMapper.selectLatestDtVersionByStrategyKeyAndGhId(key, bucketDataParam.getGhId());
+                // 判断当前的dtVersion是否已经处理过了
+                CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+                cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyDtEqualTo(dtVersion).andStrategyEqualTo(key).andGhIdEqualTo(bucketDataParam.getGhId());
+                long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
+                if (count != 0) {
+                    // 说明已处理过该dtVersion数据
+                    continue;
+                }
+                // 获取最新dt数据
+                List<AlgGhAutoreplyVideoRankData> dtVersionStrategyData = getDtVersionStrategyData(key, dtVersion, bucketDataParam.getGhId());
+                List<Long> videoIds = dtVersionStrategyData.stream().map(AlgGhAutoreplyVideoRankData::getVideoId).collect(Collectors.toList());
+                Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(videoIds);
+                result.addAll(dtVersionStrategyData.stream().map(x -> {
+                    CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+                    cgiReplyBucketData.setStrategy(key);
+                    cgiReplyBucketData.setSort(x.getSort());
+                    cgiReplyBucketData.setStrategyDt(x.getDtVersion());
+                    cgiReplyBucketData.setGhId(x.getGhId());
+                    cgiReplyBucketData.setMsgType(1);
+                    cgiReplyBucketData.setTitle(x.getTitle());
+                    VideoDetail videoDetail = videoDetailMap.get(x.getVideoId());
+                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                        cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
+                    } else {
+                        cgiReplyBucketData.setCoverUrl(CDN_URL + x.getCoverUrl());
+                    }
+                    cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
+                    cgiReplyBucketData.setMiniVideoId(x.getVideoId());
+                    return cgiReplyBucketData;
+                }).collect(Collectors.toList()));
+            }
         }
         // 获取最新数据版本
         return CollectionUtils.isEmpty(result) ? null : result;

+ 47 - 29
api-module/src/main/resources/mapper/ReplyStaffMapper.xml

@@ -5,6 +5,7 @@
     <id column="id" jdbcType="BIGINT" property="id" />
     <result column="user_id" jdbcType="VARCHAR" property="userId" />
     <result column="name" jdbcType="VARCHAR" property="name" />
+    <result column="video_ids" jdbcType="VARCHAR" property="videoIds" />
     <result column="is_delete" jdbcType="INTEGER" property="isDelete" />
     <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
     <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
@@ -68,7 +69,7 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, user_id, name, is_delete, create_time, update_time
+    id, user_id, `name`, video_ids, is_delete, create_time, update_time
   </sql>
   <select id="selectByExample" parameterType="com.tzld.piaoquan.api.model.po.ReplyStaffExample" resultMap="BaseResultMap">
     select
@@ -83,6 +84,9 @@
     <if test="orderByClause != null">
       order by ${orderByClause}
     </if>
+    <if test="page != null">
+      limit #{page.offset} , #{page.pageSize}
+    </if>
   </select>
   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
     select 
@@ -101,12 +105,12 @@
     </if>
   </delete>
   <insert id="insert" parameterType="com.tzld.piaoquan.api.model.po.ReplyStaff">
-    insert into reply_staff (id, user_id, name, 
-      is_delete, create_time, update_time
-      )
+    insert into reply_staff (id, user_id, `name`, 
+      video_ids, is_delete, create_time, 
+      update_time)
     values (#{id,jdbcType=BIGINT}, #{userId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
-      #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
-      )
+      #{videoIds,jdbcType=VARCHAR}, #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
+      #{updateTime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.tzld.piaoquan.api.model.po.ReplyStaff">
     insert into reply_staff
@@ -118,7 +122,10 @@
         user_id,
       </if>
       <if test="name != null">
-        name,
+        `name`,
+      </if>
+      <if test="videoIds != null">
+        video_ids,
       </if>
       <if test="isDelete != null">
         is_delete,
@@ -140,6 +147,9 @@
       <if test="name != null">
         #{name,jdbcType=VARCHAR},
       </if>
+      <if test="videoIds != null">
+        #{videoIds,jdbcType=VARCHAR},
+      </if>
       <if test="isDelete != null">
         #{isDelete,jdbcType=INTEGER},
       </if>
@@ -160,38 +170,42 @@
   <update id="updateByExampleSelective" parameterType="map">
     update reply_staff
     <set>
-      <if test="row.id != null">
-        id = #{row.id,jdbcType=BIGINT},
+      <if test="record.id != null">
+        id = #{record.id,jdbcType=BIGINT},
+      </if>
+      <if test="record.userId != null">
+        user_id = #{record.userId,jdbcType=VARCHAR},
       </if>
-      <if test="row.userId != null">
-        user_id = #{row.userId,jdbcType=VARCHAR},
+      <if test="record.name != null">
+        `name` = #{record.name,jdbcType=VARCHAR},
       </if>
-      <if test="row.name != null">
-        name = #{row.name,jdbcType=VARCHAR},
+      <if test="record.videoIds != null">
+        video_ids = #{record.videoIds,jdbcType=VARCHAR},
       </if>
-      <if test="row.isDelete != null">
-        is_delete = #{row.isDelete,jdbcType=INTEGER},
+      <if test="record.isDelete != null">
+        is_delete = #{record.isDelete,jdbcType=INTEGER},
       </if>
-      <if test="row.createTime != null">
-        create_time = #{row.createTime,jdbcType=TIMESTAMP},
+      <if test="record.createTime != null">
+        create_time = #{record.createTime,jdbcType=TIMESTAMP},
       </if>
-      <if test="row.updateTime != null">
-        update_time = #{row.updateTime,jdbcType=TIMESTAMP},
+      <if test="record.updateTime != null">
+        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
       </if>
     </set>
-    <if test="example != null">
+    <if test="_parameter != null">
       <include refid="Update_By_Example_Where_Clause" />
     </if>
   </update>
   <update id="updateByExample" parameterType="map">
     update reply_staff
-    set id = #{row.id,jdbcType=BIGINT},
-      user_id = #{row.userId,jdbcType=VARCHAR},
-      name = #{row.name,jdbcType=VARCHAR},
-      is_delete = #{row.isDelete,jdbcType=INTEGER},
-      create_time = #{row.createTime,jdbcType=TIMESTAMP},
-      update_time = #{row.updateTime,jdbcType=TIMESTAMP}
-    <if test="example != null">
+    set id = #{record.id,jdbcType=BIGINT},
+      user_id = #{record.userId,jdbcType=VARCHAR},
+      `name` = #{record.name,jdbcType=VARCHAR},
+      video_ids = #{record.videoIds,jdbcType=VARCHAR},
+      is_delete = #{record.isDelete,jdbcType=INTEGER},
+      create_time = #{record.createTime,jdbcType=TIMESTAMP},
+      update_time = #{record.updateTime,jdbcType=TIMESTAMP}
+    <if test="_parameter != null">
       <include refid="Update_By_Example_Where_Clause" />
     </if>
   </update>
@@ -202,7 +216,10 @@
         user_id = #{userId,jdbcType=VARCHAR},
       </if>
       <if test="name != null">
-        name = #{name,jdbcType=VARCHAR},
+        `name` = #{name,jdbcType=VARCHAR},
+      </if>
+      <if test="videoIds != null">
+        video_ids = #{videoIds,jdbcType=VARCHAR},
       </if>
       <if test="isDelete != null">
         is_delete = #{isDelete,jdbcType=INTEGER},
@@ -219,7 +236,8 @@
   <update id="updateByPrimaryKey" parameterType="com.tzld.piaoquan.api.model.po.ReplyStaff">
     update reply_staff
     set user_id = #{userId,jdbcType=VARCHAR},
-      name = #{name,jdbcType=VARCHAR},
+      `name` = #{name,jdbcType=VARCHAR},
+      video_ids = #{videoIds,jdbcType=VARCHAR},
       is_delete = #{isDelete,jdbcType=INTEGER},
       create_time = #{createTime,jdbcType=TIMESTAMP},
       update_time = #{updateTime,jdbcType=TIMESTAMP}

+ 64 - 0
api-module/src/main/resources/mybatis-api-generator-config.xml

@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE generatorConfiguration
+        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<!-- 配置生成器 -->
+<generatorConfiguration>
+    <context id="mysql" defaultModelType="flat">
+        <property name="autoDelimitKeywords" value="true"/>
+        <!-- 生成的Java文件的编码 -->
+        <property name="javaFileEncoding" value="UTF-8"/>
+        <!-- 格式化java代码 -->
+        <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
+        <!-- 格式化XML代码 -->
+        <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>
+        <!-- beginningDelimiter和endingDelimiter:指明数据库的用于标记数据库对象名的符号,比如ORACLE就是双引号,MYSQL默认是`反引号; -->
+        <property name="beginningDelimiter" value="`"/>
+        <property name="endingDelimiter" value="`"/>
+
+        <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
+        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>
+        <plugin type="com.tzld.piaoquan.api.dao.generator.PaginationPlugin"/>
+
+        <commentGenerator>
+<!--            <property name="addRemarkComments" value="true"/>-->
+            <property name="suppressDate" value="true"/>
+            <property name="suppressAllComments" value="true"/>
+        </commentGenerator>
+
+        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
+                        connectionURL="jdbc:mysql://rm-bp17q95335a99272b.mysql.rds.aliyuncs.com:3306/growth?useUnicode=true&amp;characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull&amp;useSSL=false"
+                        userId="crawler" password="crawler123456@">
+        </jdbcConnection>
+
+        <javaTypeResolver type="org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl">
+            <property name="forceBigDecimals" value="false"/>
+        </javaTypeResolver>
+
+        <javaModelGenerator targetPackage="com.tzld.piaoquan.api.model.po" targetProject="/Users/shimeng/Desktop/project/growth-manager/api-module/src/main/java">
+            <property name="constructorBased" value="false"/>
+            <property name="enableSubPackages" value="true"/>
+            <property name="immutable" value="false"/>
+        </javaModelGenerator>
+
+        <sqlMapGenerator targetPackage="mapper" targetProject="/Users/shimeng/Desktop/project/growth-manager/api-module/src/main/resources">
+            <property name="enableSubPackages" value="true"/>
+        </sqlMapGenerator>
+
+        <javaClientGenerator targetPackage="com.tzld.piaoquan.api.dao.mapper" type="XMLMAPPER"
+                             targetProject="/Users/shimeng/Desktop/project/growth-manager/api-module/src/main/java">
+            <property name="enableSubPackages" value="true"/>
+        </javaClientGenerator>
+
+<!--        <table tableName="we_com_alert_message" domainObjectName="AlertMessage" alias=""/>-->
+<!--        <table tableName="gh_detail" domainObjectName="GhDetail" alias=""/>-->
+<!--        <table tableName="we_com_guarantees_video" domainObjectName="GuaranteesVideo" alias=""/>-->
+<!--        <table tableName="we_com_staff" domainObjectName="Staff" alias=""/>-->
+<!--        <table tableName="we_com_message_attachment" domainObjectName="MessageAttachment" alias=""/>-->
+        <table tableName="reply_staff" domainObjectName="ReplyStaff" alias=""/>
+<!--        <table tableName="we_com_send_msg_result" domainObjectName="SendMsgResult" alias=""/>-->
+<!--        <table tableName="we_com_corp" domainObjectName="Corp" alias=""/>-->
+
+    </context>
+
+</generatorConfiguration>