Browse Source

三方平台群消息发送 视频选取

wangyunpeng 1 week ago
parent
commit
100a882d96

+ 17 - 0
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/contentplatform/ext/ContentPlatformPlanMapperExt.java

@@ -45,6 +45,23 @@ public interface ContentPlatformPlanMapperExt {
                                             @Param("pageSize") Integer pageSize,
                                             @Param("sort") String sort);
 
+    List<ContentPlatformVideo> getVideoMinScoreList(@Param("dt") String dt,
+                                                    @Param("minScore") Double minScore,
+                                                    @Param("excludeVideoIds") List<Long> excludeVideoIds,
+                                                    @Param("offset") int offset,
+                                                    @Param("pageSize") Integer pageSize,
+                                                    @Param("sort") String sort);
+
+    List<ContentPlatformVideo> getVideoMinDatastatScoreList(@Param("dt") String dt,
+                                                            @Param("datastatDt") String datastatDt,
+                                                            @Param("type") String type,
+                                                            @Param("channel") String channel,
+                                                            @Param("minScore") Double minScore,
+                                                            @Param("excludeVideoIds") List<Long> excludeVideoIds,
+                                                            @Param("offset") int offset,
+                                                            @Param("pageSize") Integer pageSize,
+                                                            @Param("sort") String sort);
+
     void batchInsertContentPlatformVideo(@Param("records") List<ContentPlatformVideo> saveList);
 
     void batchInsertContentPlatformVideoAgg(@Param("records") List<ContentPlatformVideoAgg> saveList);

+ 60 - 5
api-module/src/main/java/com/tzld/piaoquan/api/job/wecom/thirdpart/WeComSendMsgJob.java

@@ -2,22 +2,31 @@ package com.tzld.piaoquan.api.job.wecom.thirdpart;
 
 import com.alibaba.fastjson.JSONObject;
 import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
+import com.tzld.piaoquan.api.dao.mapper.contentplatform.ext.ContentPlatformPlanMapperExt;
 import com.tzld.piaoquan.api.dao.mapper.wecom.thirdpart.ThirdPartWeComMsgMapper;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.CdnUploadImgLinkRequest;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.CdnUploadImgLinkResponse;
 import com.tzld.piaoquan.api.model.param.wecom.thirdpart.SendAppMsgRequest;
+import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComMsg;
+import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComMsgExample;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComRoom;
 import com.tzld.piaoquan.api.model.po.wecom.thirdpart.ThirdPartWeComStaff;
 import com.tzld.piaoquan.api.service.WeComThirdPartyService;
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
+import com.tzld.piaoquan.growth.common.model.po.Staff;
+import com.tzld.piaoquan.growth.common.service.MessageAttachmentService;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
 import com.xxl.job.core.biz.model.ReturnT;
 import com.xxl.job.core.handler.annotation.XxlJob;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Component
@@ -26,11 +35,20 @@ public class WeComSendMsgJob {
     @Autowired
     WeComThirdPartyService weComThirdPartyService;
     @Autowired
+    MessageAttachmentService messageAttachmentService;
+    @Autowired
+    ContentPlatformPlanMapperExt planMapperExt;
+    @Autowired
     ThirdPartWeComMsgMapper thirdPartWeComMsgMapper;
 
     @ApolloJsonValue("${wecom.thirdpart.send.msg.config:{}}")
     private JSONObject sendMsgConfig;
 
+    @Value("${send.room.msg.video.min.score:3}")
+    private Double videoMinScore;
+    @Value("${send.room.msg.duplicate.days:7}")
+    private Integer duplicateDays;
+
     @XxlJob("autoSendAppMsg")
     public ReturnT<String> autoSendAppMsg(String param) {
         List<ThirdPartWeComStaff> activeStaffList = weComThirdPartyService.getActiveStaffList();
@@ -56,14 +74,14 @@ public class WeComSendMsgJob {
                     request.setAppName("票圈Vlog");
                     request.setTitle("票圈Vlog");
                     request.setWeappIconUrl("http://rescdn.yishihui.com/temp/1755515422185_%E7%A5%A8%E5%9C%88Vlog_logo.jpg");
-                    // todo 选取视频
-
+                    // 选取视频
+                    CgiReplyBucketData cgiReplyBucketData = getCgiReplyBucketData(room.getId(), staff);
                     // 填充视频信息
-                    request.setDesc("标题");
-                    request.setPagepath("pages/index/index");
+                    request.setDesc(cgiReplyBucketData.getTitle());
+                    request.setPagepath(cgiReplyBucketData.getMiniPagePath());
                     CdnUploadImgLinkRequest cdnUploadImgLinkRequest = new CdnUploadImgLinkRequest();
                     cdnUploadImgLinkRequest.setUuid(staff.getThirdUuid());
-                    cdnUploadImgLinkRequest.setUrl("cover");
+                    cdnUploadImgLinkRequest.setUrl(cgiReplyBucketData.getMiniPagePath());
                     CdnUploadImgLinkResponse uploadResponse = weComThirdPartyService.cdnUploadImgLink(cdnUploadImgLinkRequest);
                     request.setCdnkey(uploadResponse.getCdn_key());
                     request.setMd5(uploadResponse.getMd5());
@@ -79,6 +97,43 @@ public class WeComSendMsgJob {
         return ReturnT.SUCCESS;
     }
 
+    private CgiReplyBucketData getCgiReplyBucketData(Long roomId, ThirdPartWeComStaff thirdPartWeComStaff) {
+        String dt = planMapperExt.getVideoMaxDt();
+        String datastatDt = planMapperExt.getVideoDatastatMaxDt();
+        // 排除最近发送过的视频
+        List<Long> sentVideoIds = getSentVideoIds(roomId);
+        // 按行业获取视频
+        String sort = "datastat.fission_rate desc, video.score desc";
+        String type = "企微-社群";
+        String channel = "sum";
+        List<ContentPlatformVideo> videoList = planMapperExt.getVideoMinDatastatScoreList(dt, datastatDt,
+                type, channel, videoMinScore, sentVideoIds, 0, 100, sort);
+        if (CollectionUtils.isEmpty(videoList)) {
+            // 行业数量不足,按平台推荐top选取视频
+            sort = "video.score desc";
+            videoList = planMapperExt.getVideoMinScoreList(dt, videoMinScore, sentVideoIds, 0, 100, sort);
+        }
+        ContentPlatformVideo video = videoList.get(0);
+        Staff staff = new Staff();
+        staff.setCarrierId(String.valueOf(thirdPartWeComStaff.getThirdStaffId()));
+        staff.setRemark(thirdPartWeComStaff.getName());
+        String page = messageAttachmentService.getPage(staff, video.getVideoId());
+
+        CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
+        cgiReplyBucketData.setTitle(video.getTitle());
+        cgiReplyBucketData.setCoverUrl(video.getCover());
+        cgiReplyBucketData.setMiniPagePath(page);
+        return cgiReplyBucketData;
+    }
+
+    private List<Long> getSentVideoIds(Long roomId) {
+        ThirdPartWeComMsgExample msgExample = new ThirdPartWeComMsgExample();
+        msgExample.createCriteria().andSendUseridEqualTo(roomId)
+                .andCreateTimeGreaterThan(DateUtil.getDaysAgoDate(duplicateDays));
+        List<ThirdPartWeComMsg> msgList = thirdPartWeComMsgMapper.selectByExample(msgExample);
+        return msgList.stream().map(ThirdPartWeComMsg::getVideoId).collect(Collectors.toList());
+    }
+
     private void saveWeComMsg(Long staffId, Long videoId, SendAppMsgRequest request) {
         ThirdPartWeComMsg msg = new ThirdPartWeComMsg();
         msg.setStaffId(staffId);

+ 30 - 0
api-module/src/main/resources/mapper/contentplatform/ext/ContentPlatformPlanMapperExt.xml

@@ -126,6 +126,36 @@
         limit #{offset}, #{pageSize}
     </select>
 
+    <select id="getVideoMinScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
+        select *
+        from content_platform_video_agg video
+        where video.dt = #{dt} and video.status = 1 and video.score > #{minScore}
+        <if test="excludeVideoIds != null and excludeVideoIds.size() > 0">
+            and video.video_id not in
+            <foreach collection="excludeVideoIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        limit #{offset}, #{pageSize}
+    </select>
+
+    <select id="getVideoMinDatastatScoreList" resultType="com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformVideo">
+        select video.*
+        from content_platform_video_agg video
+        left join content_platform_video_datastat_agg datastat
+            on datastat.dt = #{datastatDt} and datastat.type = #{type} and datastat.channel = #{channel} and datastat.video_id = video.video_id
+        where video.dt = #{dt} and video.status = 1 and datastat.fission_rate > #{minScore}
+        <if test="excludeVideoIds != null and excludeVideoIds.size() > 0">
+            and video.video_id not in
+            <foreach collection="excludeVideoIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+        order by ${sort}
+        limit #{offset}, #{pageSize}
+    </select>
+
     <select id="getVideoCategoryList" resultType="java.lang.String">
         select distinct category
         from content_platform_video_agg