|
@@ -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);
|