Преглед изворни кода

Merge branch '20251211-wyp-gzhAutoReplyVideo' of Server/growth-manager into master

wangyunpeng пре 1 недеља
родитељ
комит
f33057592f
18 измењених фајлова са 341 додато и 101 уклоњено
  1. 6 0
      api-module/src/main/java/com/tzld/piaoquan/api/component/AigcApiService.java
  2. 3 2
      api-module/src/main/java/com/tzld/piaoquan/api/controller/AccountDetailController.java
  3. 2 2
      api-module/src/main/java/com/tzld/piaoquan/api/dao/generator/MybatisGeneratorMain.java
  4. 0 5
      api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/GhDetailExtMapper.java
  5. 17 0
      api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/GhDetailMapperExt.java
  6. 0 1
      api-module/src/main/java/com/tzld/piaoquan/api/model/bo/BucketDataParam.java
  7. 11 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/po/GhDetailExt.java
  8. 60 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/po/GhDetailExtExample.java
  9. 10 0
      api-module/src/main/java/com/tzld/piaoquan/api/model/vo/GhDetailVo.java
  10. 1 1
      api-module/src/main/java/com/tzld/piaoquan/api/service/GhDetailService.java
  11. 14 13
      api-module/src/main/java/com/tzld/piaoquan/api/service/impl/CgiReplyServiceImpl.java
  12. 131 6
      api-module/src/main/java/com/tzld/piaoquan/api/service/impl/GhDetailServiceImpl.java
  13. 19 30
      api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/BuckStrategyV1.java
  14. 17 7
      api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/ThirdPartyPushMessageStrategyV1.java
  15. 0 21
      api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/impl/ThirdPartyServiceImpl.java
  16. 24 9
      api-module/src/main/resources/mapper/GhDetailExtMapper.xml
  17. 22 0
      api-module/src/main/resources/mapper/GhDetailMapperExt.xml
  18. 4 4
      api-module/src/main/resources/mybatis-api-generator-config.xml

+ 6 - 0
api-module/src/main/java/com/tzld/piaoquan/api/component/AigcApiService.java

@@ -26,6 +26,9 @@ public class AigcApiService {
     @Value("${aigc.api.token:9ebfcb397e954c41986971f183eb1707}")
     private String aigcApiToken;
 
+    @Value("${spring.profiles.active:dev}")
+    private String env;
+
     private String getAigcPostParam(JSONObject params) {
         JSONObject baseInfo = JSONObject.parseObject("{\n" +
                 "    \"token\": \"" + aigcApiToken + "\",\n" +
@@ -211,6 +214,9 @@ public class AigcApiService {
     }
 
     public void refreshGzhAutoReplyMsgData(String ghId) {
+        if (!"prod".equals(env)) {
+            return;
+        }
         String url = aigcApiHost + "/publish/api/refreshGzhAutoReplyMsgData?ghId=" + ghId;
         try {
             httpPoolClient.get(url);

+ 3 - 2
api-module/src/main/java/com/tzld/piaoquan/api/controller/AccountDetailController.java

@@ -30,8 +30,9 @@ public class AccountDetailController {
     public CommonResponse<Page<GhDetailVo>> getAccountDetailList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(defaultValue = "20") Integer pageSize,
                                                                  @RequestParam(defaultValue = "") String accountId,
-                                                                 @RequestParam(defaultValue = "") String accountName) {
-        return ghDetailService.getGhDetailList(pageNum, pageSize, accountId, accountName);
+                                                                 @RequestParam(defaultValue = "") String accountName,
+                                                                 @RequestParam(required = false) Long videoId) {
+        return ghDetailService.getGhDetailList(pageNum, pageSize, accountId, accountName, videoId);
     }
 
     @PostMapping("/add")

+ 2 - 2
api-module/src/main/java/com/tzld/piaoquan/api/dao/generator/MybatisGeneratorMain.java

@@ -21,9 +21,9 @@ public class MybatisGeneratorMain {
         List<String> warnings = new ArrayList<>();
 
         //File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-generator-config.xml").getFile());
-//        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-generator-config.xml").getFile());
+        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-generator-config.xml").getFile());
 //        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-contentPlatform-generator-config.xml").getFile());
-        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-wecomThirdpart-generator-config.xml").getFile());
+//        File configFile = new File(MybatisGeneratorMain.class.getResource("/mybatis-api-wecomThirdpart-generator-config.xml").getFile());
         ConfigurationParser cp = new ConfigurationParser(warnings);
         Configuration config = cp.parseConfiguration(configFile);
         DefaultShellCallback callback = new DefaultShellCallback(true);

+ 0 - 5
api-module/src/main/java/com/tzld/piaoquan/api/dao/mapper/GhDetailExtMapper.java

@@ -3,13 +3,8 @@ package com.tzld.piaoquan.api.dao.mapper;
 import com.tzld.piaoquan.api.model.po.GhDetailExt;
 import com.tzld.piaoquan.api.model.po.GhDetailExtExample;
 import java.util.List;
-
-import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
-import org.springframework.stereotype.Repository;
 
-@Mapper
-@Repository
 public interface GhDetailExtMapper {
     long countByExample(GhDetailExtExample example);
 

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

@@ -0,0 +1,17 @@
+package com.tzld.piaoquan.api.dao.mapper;
+
+import com.tzld.piaoquan.api.model.po.GhDetailExt;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+@Mapper
+@Repository
+public interface GhDetailMapperExt {
+
+    void deleteOldGhDetailExt(@Param("ghId") String ghId, @Param("type") Integer type);
+
+    void batchInsertGhDetailExt(@Param("records") List<GhDetailExt> records);
+}

+ 0 - 1
api-module/src/main/java/com/tzld/piaoquan/api/model/bo/BucketDataParam.java

@@ -1,6 +1,5 @@
 package com.tzld.piaoquan.api.model.bo;
 
-import com.tzld.piaoquan.api.model.po.GhDetailExt;
 import lombok.Data;
 
 import java.util.List;

+ 11 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/po/GhDetailExt.java

@@ -7,6 +7,8 @@ public class GhDetailExt {
 
     private Long ghDetailId;
 
+    private Long videoId;
+
     private String page;
 
     private String title;
@@ -37,6 +39,14 @@ public class GhDetailExt {
         this.ghDetailId = ghDetailId;
     }
 
+    public Long getVideoId() {
+        return videoId;
+    }
+
+    public void setVideoId(Long videoId) {
+        this.videoId = videoId;
+    }
+
     public String getPage() {
         return page;
     }
@@ -101,6 +111,7 @@ public class GhDetailExt {
         sb.append("Hash = ").append(hashCode());
         sb.append(", id=").append(id);
         sb.append(", ghDetailId=").append(ghDetailId);
+        sb.append(", videoId=").append(videoId);
         sb.append(", page=").append(page);
         sb.append(", title=").append(title);
         sb.append(", cover=").append(cover);

+ 60 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/po/GhDetailExtExample.java

@@ -236,6 +236,66 @@ public class GhDetailExtExample {
             return (Criteria) this;
         }
 
+        public Criteria andVideoIdIsNull() {
+            addCriterion("video_id is null");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdIsNotNull() {
+            addCriterion("video_id is not null");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdEqualTo(Long value) {
+            addCriterion("video_id =", value, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdNotEqualTo(Long value) {
+            addCriterion("video_id <>", value, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdGreaterThan(Long value) {
+            addCriterion("video_id >", value, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdGreaterThanOrEqualTo(Long value) {
+            addCriterion("video_id >=", value, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdLessThan(Long value) {
+            addCriterion("video_id <", value, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdLessThanOrEqualTo(Long value) {
+            addCriterion("video_id <=", value, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdIn(List<Long> values) {
+            addCriterion("video_id in", values, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdNotIn(List<Long> values) {
+            addCriterion("video_id not in", values, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdBetween(Long value1, Long value2) {
+            addCriterion("video_id between", value1, value2, "videoId");
+            return (Criteria) this;
+        }
+
+        public Criteria andVideoIdNotBetween(Long value1, Long value2) {
+            addCriterion("video_id not between", value1, value2, "videoId");
+            return (Criteria) this;
+        }
+
         public Criteria andPageIsNull() {
             addCriterion("page is null");
             return (Criteria) this;

+ 10 - 0
api-module/src/main/java/com/tzld/piaoquan/api/model/vo/GhDetailVo.java

@@ -29,6 +29,8 @@ public class GhDetailVo {
 
     private List<Long> videoIds;
 
+    private List<VideoDetail> videoList;
+
     private Integer strategyStatus;
 
     private String strategyStatusName;
@@ -38,4 +40,12 @@ public class GhDetailVo {
     private String rate;
 
     private String contentDetail;
+
+    @Data
+    public static class VideoDetail {
+        private Long videoId;
+        private Integer sort;
+        private String title;
+        private String cover;
+    }
 }

+ 1 - 1
api-module/src/main/java/com/tzld/piaoquan/api/service/GhDetailService.java

@@ -10,7 +10,7 @@ import java.util.List;
 
 public interface GhDetailService {
 
-    CommonResponse<Page<GhDetailVo>> getGhDetailList(Integer pageNum, Integer pageSize, String accountId, String accountName);
+    CommonResponse<Page<GhDetailVo>> getGhDetailList(Integer pageNum, Integer pageSize, String accountId, String accountName, Long videoId);
 
     CommonResponse<Void> addGhDetail(GhDetailVo ghDetailVo);
 

+ 14 - 13
api-module/src/main/java/com/tzld/piaoquan/api/service/impl/CgiReplyServiceImpl.java

@@ -30,7 +30,10 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.PostConstruct;
-import java.util.*;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 
 @Service
 public class CgiReplyServiceImpl implements CgiReplyService {
@@ -78,21 +81,19 @@ public class CgiReplyServiceImpl implements CgiReplyService {
         if (StringUtils.isNotEmpty(ghDetail.getVideoIds())) {
             bucketDataParam.setVideos(JSONArray.parseArray(ghDetail.getVideoIds(), Long.class));
         }
-        GhDetailExtExample ghDetailExtExample = new GhDetailExtExample();
-        ghDetailExtExample.createCriteria().andGhDetailIdEqualTo(ghDetail.getId()).andIsDeleteEqualTo(0);
-        ghDetailExtExample.setOrderByClause("sort desc, id asc");
-        List<GhDetailExt> ghDetailExts = ghDetailExtMapper.selectByExample(ghDetailExtExample);
+        GhDetailExtExample extExample = new GhDetailExtExample();
+        extExample.createCriteria().andGhDetailIdEqualTo(ghDetail.getId()).andIsDeleteEqualTo(0);
+        List<GhDetailExt> ghDetailExts = ghDetailExtMapper.selectByExample(extExample);
         if (!CollectionUtils.isEmpty(ghDetailExts)) {
-            List<MiniPageData> miniPageDatas = new ArrayList<>();
-            for (GhDetailExt ghDetailExt : ghDetailExts) {
+            bucketDataParam.setMiniPageDatas(ghDetailExts.stream().sorted(Comparator.comparing(GhDetailExt::getSort)).map(ext -> {
                 MiniPageData miniPageData = new MiniPageData();
-                miniPageData.setCover(ghDetailExt.getCover());
-                miniPageData.setPage(ghDetailExt.getPage());
-                miniPageData.setTitle(ghDetailExt.getTitle());
-                miniPageDatas.add(miniPageData);
-            }
-            bucketDataParam.setMiniPageDatas(miniPageDatas);
+                miniPageData.setPage(ext.getPage());
+                miniPageData.setTitle(ext.getTitle());
+                miniPageData.setCover(ext.getCover());
+                return miniPageData;
+            }).collect(java.util.stream.Collectors.toList()));
         }
+
         if (Objects.equals(ghDetail.getType(), GhTypeEnum.THIRD_PARTY_GH.type)) {
             bucketDataParam.setChannel(ghDetail.getChannel());
             return getPushMessageData(bucketDataParam);

+ 131 - 6
api-module/src/main/java/com/tzld/piaoquan/api/service/impl/GhDetailServiceImpl.java

@@ -1,13 +1,23 @@
 package com.tzld.piaoquan.api.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.api.component.AigcApiService;
+import com.tzld.piaoquan.api.component.TouLiuHttpClient;
+import com.tzld.piaoquan.api.dao.mapper.GhDetailExtMapper;
+import com.tzld.piaoquan.api.dao.mapper.GhDetailMapperExt;
+import com.tzld.piaoquan.api.model.po.GhDetailExt;
+import com.tzld.piaoquan.api.model.po.GhDetailExtExample;
 import com.tzld.piaoquan.api.model.vo.GhDetailVo;
 import com.tzld.piaoquan.api.service.GhDetailService;
 import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
 import com.tzld.piaoquan.growth.common.common.enums.GhTypeEnum;
 import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
+import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
 import com.tzld.piaoquan.growth.common.dao.mapper.GhDetailMapper;
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
+import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketDataExample;
 import com.tzld.piaoquan.growth.common.model.po.GhDetail;
 import com.tzld.piaoquan.growth.common.model.po.GhDetailExample;
 import com.tzld.piaoquan.growth.common.utils.DateUtil;
@@ -16,13 +26,12 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
@@ -30,11 +39,25 @@ public class GhDetailServiceImpl implements GhDetailService {
 
     @Autowired
     private GhDetailMapper ghDetailMapper;
+    @Autowired
+    private GhDetailExtMapper ghDetailExtMapper;
+    @Autowired
+    private GhDetailMapperExt ghDetailMapperExt;
+    @Autowired
+    private AigcApiService aigcApiService;
+    @Autowired
+    private TouLiuHttpClient touLiuHttpClient;
+    @Autowired
+    private CgiReplyBucketDataMapper cgiReplyBucketDataMapper;
 
+    @Value("${small_page_url}")
+    private String GET_SMALL_PAGE_URL;
+    @Value("${rootSourceConfig:{}}")
+    private String rootSourceConfig;
 
     @Override
     public CommonResponse<Page<GhDetailVo>> getGhDetailList(Integer pageNum, Integer pageSize,
-                                                            String accountId, String accountName) {
+                                                            String accountId, String accountName, Long videoId) {
         if (pageNum == null) {
             pageNum = 1;
         }
@@ -56,12 +79,20 @@ public class GhDetailServiceImpl implements GhDetailService {
         if (StringUtils.isNotEmpty(accountName)) {
             criteria.andGhNameLike("%" + accountName + "%");
         }
+        if (Objects.nonNull(videoId)) {
+            criteria.andVideoIdsLike("%" + videoId + "%");
+        }
         example.setPage(page);
         long total = ghDetailMapper.countByExample(example);
         page.setTotalSize((int) total);
         List<GhDetail> ghDetails = ghDetailMapper.selectByExample(example);
         List<GhDetailVo> ghDetailVos = new ArrayList<>();
         if (!CollectionUtils.isEmpty(ghDetails)) {
+            List<Long> ghDetailIds = ghDetails.stream().map(GhDetail::getId).collect(Collectors.toList());
+            GhDetailExtExample exampleExt = new GhDetailExtExample();
+            exampleExt.createCriteria().andGhDetailIdIn(ghDetailIds).andIsDeleteEqualTo(0);
+            List<GhDetailExt> ghDetailExts = ghDetailExtMapper.selectByExample(exampleExt);
+            Map<Long, List<GhDetailExt>> ghDetailExtMap = ghDetailExts.stream().collect(Collectors.groupingBy(GhDetailExt::getGhDetailId));
             for (GhDetail ghDetail : ghDetails) {
                 GhDetailVo ghDetailVo = new GhDetailVo();
                 BeanUtils.copyProperties(ghDetail, ghDetailVo);
@@ -74,6 +105,20 @@ public class GhDetailServiceImpl implements GhDetailService {
                 if (StringUtils.isNotEmpty(ghDetail.getVideoIds())) {
                     List<Long> videoIds = JSONObject.parseArray(ghDetail.getVideoIds(), Long.class);
                     ghDetailVo.setVideoIds(videoIds);
+                    List<GhDetailExt> videoExts = ghDetailExtMap.get(ghDetail.getId());
+                    if (!CollectionUtils.isEmpty(videoExts)) {
+                        videoExts.sort(Comparator.comparing(GhDetailExt::getSort));
+                        List<GhDetailVo.VideoDetail> videoList = new ArrayList<>();
+                        for (GhDetailExt videoExt : videoExts) {
+                            GhDetailVo.VideoDetail videoDetail = new GhDetailVo.VideoDetail();
+                            videoDetail.setVideoId(videoExt.getVideoId());
+                            videoDetail.setSort(videoExt.getSort());
+                            videoDetail.setTitle(videoExt.getTitle());
+                            videoDetail.setCover(videoExt.getCover());
+                            videoList.add(videoDetail);
+                        }
+                        ghDetailVo.setVideoList(videoList);
+                    }
                 }
                 ghDetailVo.setStrategyStatusName(StrategyStatusEnum.getStrategyStatusName(ghDetail.getStrategyStatus()));
                 ghDetailVos.add(ghDetailVo);
@@ -117,6 +162,9 @@ public class GhDetailServiceImpl implements GhDetailService {
                 ghDetail.setContentDetail(null);
             }
             ghDetailMapper.insertSelective(ghDetail);
+            ghDetailMapperExt.deleteOldGhDetailExt(ghDetailVo.getAccountId(), ghDetailVo.getType());
+            batchSaveGhDetailExt(ghDetailVo);
+            aigcApiService.refreshGzhAutoReplyMsgData(ghDetailVo.getAccountId());
             return CommonResponse.success();
         } catch (Exception e) {
             log.error("addGhDetail error", e);
@@ -124,6 +172,70 @@ public class GhDetailServiceImpl implements GhDetailService {
         return CommonResponse.create(500, "插入失败");
     }
 
+    private void batchSaveGhDetailExt(GhDetailVo ghDetailVo) {
+        if (CollectionUtils.isEmpty(ghDetailVo.getVideoIds())) {
+            return;
+        }
+        GhDetail ghDetail = getGhDetailByGhIdType(ghDetailVo.getAccountId(), ghDetailVo.getType());
+        if (ghDetail == null) {
+            return;
+        }
+        List<GhDetailExt> ghDetailExts = new ArrayList<>();
+        for (GhDetailVo.VideoDetail videoDetail : ghDetailVo.getVideoList()) {
+            GhDetailExt ghDetailExt = new GhDetailExt();
+            ghDetailExt.setGhDetailId(ghDetail.getId());
+            ghDetailExt.setVideoId(videoDetail.getVideoId());
+            ghDetailExt.setPage(getVideoPageUrl(videoDetail.getVideoId(), ghDetailVo.getChannel(),
+                    ghDetailVo.getAccountId(), videoDetail.getSort(), ghDetailVo.getType()));
+            ghDetailExt.setTitle(videoDetail.getTitle());
+            ghDetailExt.setCover(videoDetail.getCover());
+            ghDetailExt.setSort(videoDetail.getSort());
+            ghDetailExt.setIsDelete(0);
+            ghDetailExts.add(ghDetailExt);
+        }
+        ghDetailMapperExt.batchInsertGhDetailExt(ghDetailExts);
+    }
+
+    private String getVideoPageUrl(Long videoId, String channel, String ghId, Integer sort, Integer accountType) {
+        // 查询库里是否存在,如果存在即复用
+        try {
+            CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
+            cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andMiniVideoIdEqualTo(videoId).andGhIdEqualTo(ghId);
+            List<CgiReplyBucketData> cgiReplyBucketData = cgiReplyBucketDataMapper.selectByExample(cgiReplyBucketDataExample);
+            if (!CollectionUtils.isEmpty(cgiReplyBucketData)) {
+                return cgiReplyBucketData.get(0).getPagePathUrlId().toString();
+            }
+            String response;
+            if (accountType.equals(GhTypeEnum.GH.type)) {
+                String putScene = "touliu";
+                channel = "tencentgzh";
+                JSONObject rootSourceConfigs = JSON.parseObject(rootSourceConfig);
+                JSONObject jsonObject1 = rootSourceConfigs.getJSONObject(ghId);
+                if (jsonObject1 != null) {
+                    if (StringUtils.isNotEmpty(jsonObject1.getString("putScene"))) {
+                        putScene = jsonObject1.getString("putScene");
+                    }
+                    if (StringUtils.isNotEmpty(jsonObject1.getString("channel"))) {
+                        channel = jsonObject1.getString("channel");
+                    }
+                }
+                response = touLiuHttpClient.sendAdFlowAddRequest(GET_SMALL_PAGE_URL, String.valueOf(videoId), putScene, channel, "自动", "公众号", "自动回复小程序", "位置" + sort, ghId);
+            } else {
+                response = touLiuHttpClient.sendAdFlowAddRequest(GET_SMALL_PAGE_URL, String.valueOf(videoId), "dyyjs", channel, "自动", "公众号", "自动回复小程序", "位置" + sort, ghId);
+            }
+            JSONObject jsonObject = JSON.parseObject(response);
+            if (jsonObject != null && jsonObject.containsKey("data")) {
+                JSONObject data = jsonObject.getJSONObject("data");
+                if (data != null && data.containsKey("url")) {
+                    return data.getString("url");
+                }
+            }
+        } catch (Exception e) {
+            log.error("getVideoPageUrl error", e);
+        }
+        return null;
+    }
+
     @Override
     public CommonResponse<Void> updateDetail(GhDetailVo ghDetailVo) {
         if (ghDetailVo == null || ghDetailVo.getId() == null) {
@@ -149,6 +261,8 @@ public class GhDetailServiceImpl implements GhDetailService {
             ghDetail.setGhName(ghDetailVo.getAccountName());
             ghDetail.setVideoIds(JSONObject.toJSONString(ghDetailVo.getVideoIds()));
             ghDetailMapper.updateByPrimaryKeySelective(ghDetail);
+            ghDetailMapperExt.deleteOldGhDetailExt(ghDetailVo.getAccountId(), ghDetailVo.getType());
+            batchSaveGhDetailExt(ghDetailVo);
 
             if (StringUtils.isEmpty(ghDetail.getContentDetail()) || StringUtils.isEmpty(ghDetail.getRate())) {
                 GhDetail updateGhDetail = ghDetailMapper.selectByPrimaryKey(ghDetail.getId());
@@ -161,7 +275,7 @@ public class GhDetailServiceImpl implements GhDetailService {
                 updateGhDetail.setUpdateTime(new Date());
                 ghDetailMapper.updateByPrimaryKey(updateGhDetail);
             }
-
+            aigcApiService.refreshGzhAutoReplyMsgData(ghDetailVo.getAccountId());
 
             return CommonResponse.success();
         } catch (Exception e) {
@@ -200,6 +314,17 @@ public class GhDetailServiceImpl implements GhDetailService {
             }
         }
 
+        if (!CollectionUtils.isEmpty(ghDetailVo.getVideoList())) {
+            for (GhDetailVo.VideoDetail videoDetail : ghDetailVo.getVideoList()) {
+                if (StringUtils.isEmpty(videoDetail.getTitle())) {
+                    return CommonResponse.create(500, "视频标题不能为空");
+                }
+                if (StringUtils.isEmpty(videoDetail.getCover())) {
+                    return CommonResponse.create(500, "视频封面不能为空");
+                }
+            }
+        }
+
         if (StringUtils.isNotEmpty(ghDetailVo.getContentDetail())) {
             ghDetailVo.setContentDetail(ghDetailVo.getContentDetail().trim());
             if (!JSONObject.isValidObject(ghDetailVo.getContentDetail())) {

+ 19 - 30
api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/BuckStrategyV1.java

@@ -6,18 +6,16 @@ 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.api.model.po.contentplatform.ContentPlatformGzhPlanVideo;
+import com.tzld.piaoquan.api.model.bo.*;
+import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankData;
+import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankDataExample;
 import com.tzld.piaoquan.api.model.vo.VideoCharacteristicVO;
-import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
+import com.tzld.piaoquan.api.service.strategy.ReplyStrategyService;
 import com.tzld.piaoquan.growth.common.common.enums.StrategyStatusEnum;
 import com.tzld.piaoquan.growth.common.dao.mapper.CgiReplyBucketDataMapper;
 import com.tzld.piaoquan.growth.common.dao.mapper.GhDetailMapper;
-import com.tzld.piaoquan.api.model.bo.*;
-import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankData;
-import com.tzld.piaoquan.api.model.po.AlgGhAutoreplyVideoRankDataExample;
 import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketData;
 import com.tzld.piaoquan.growth.common.model.po.CgiReplyBucketDataExample;
-import com.tzld.piaoquan.api.service.strategy.ReplyStrategyService;
 import com.tzld.piaoquan.growth.common.utils.MessageUtil;
 import com.tzld.piaoquan.growth.common.utils.RedisUtils;
 import lombok.extern.slf4j.Slf4j;
@@ -75,8 +73,6 @@ public class BuckStrategyV1 implements ReplyStrategyService {
     private TouLiuHttpClient touLiuHttpClient;
     @Autowired
     private GhDetailMapper ghDetailMapper;
-    @Autowired
-    private ContentPlatformPlanService contentPlatformPlanService;
 
     @Autowired
     private RedisUtils redisUtils;
@@ -417,8 +413,10 @@ public class BuckStrategyV1 implements ReplyStrategyService {
                 //}
             }
 
+            Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
             for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
                 int sort = i + 1;
+                Long videoId = bucketDataParam.getVideos().get(i);
                 MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
                 CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
                 cgiReplyBucketData.setStrategy(key);
@@ -426,6 +424,13 @@ public class BuckStrategyV1 implements ReplyStrategyService {
                 cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
                 cgiReplyBucketData.setMsgType(1);
                 cgiReplyBucketData.setCoverUrl(miniPageData.getCover());
+                // 替换封面参数
+                VideoDetail videoDetail = videoDetailMap.get(videoId);
+                if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                    if (videoDetail.getCover().contains("?")) {
+                        cgiReplyBucketData.setCoverUrl(miniPageData.getCover() + videoDetail.getCover().substring(videoDetail.getCover().indexOf("?")));
+                    }
+                }
                 cgiReplyBucketData.setTitle(miniPageData.getTitle());
                 cgiReplyBucketData.setMiniPagePath(miniPageData.getPage());
                 cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
@@ -450,37 +455,21 @@ public class BuckStrategyV1 implements ReplyStrategyService {
                 //    continue;
                 //}
             }
+            Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
             for (int i = 0; i < bucketDataParam.getVideos().size(); i++) {
                 int sort = i + 1;
                 Long videoId = bucketDataParam.getVideos().get(i);
-                Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
-                List<ContentPlatformGzhPlanVideo> gzhPlanVideoList = contentPlatformPlanService.getGzhPlanVideoListByCooperateAccountId(bucketDataParam.getGhId());
-                Map<Long, ContentPlatformGzhPlanVideo> gzhPlanVideoMap = gzhPlanVideoList.stream().collect(Collectors.toMap(ContentPlatformGzhPlanVideo::getVideoId, x -> x));
                 CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
                 cgiReplyBucketData.setStrategy(key);
                 cgiReplyBucketData.setSort(sort);
                 cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
                 cgiReplyBucketData.setMsgType(1);
                 VideoDetail videoDetail = videoDetailMap.get(videoId);
-                ContentPlatformGzhPlanVideo gzhPlanVideo = gzhPlanVideoMap.get(videoId);
-                // 内容合作平台视频标题和封面
-                if (Objects.nonNull(gzhPlanVideo) && Objects.nonNull(videoDetail)) {
-                    cgiReplyBucketData.setTitle(ContentPlatformPlanService.getVideoTitle(gzhPlanVideo));
-                    String cover = ContentPlatformPlanService.getVideoCover(gzhPlanVideo);
-                    if (StringUtils.isNotEmpty(cover)) {
-                        String coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("?"));
-                        if (cover.contains("?") && cover.contains("image/resize")) {
-                            coverSuffix = videoDetail.getCover().substring(videoDetail.getCover().indexOf("/watermark"));
-                        }
-                        cgiReplyBucketData.setCoverUrl(cover + coverSuffix);
-                    }
-                } else {
-                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
-                        cgiReplyBucketData.setCoverUrl(videoDetail.getCover());
-                    }
-                    if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getTitle())) {
-                        cgiReplyBucketData.setTitle(videoDetail.getTitle());
-                    }
+                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);

+ 17 - 7
api-module/src/main/java/com/tzld/piaoquan/api/service/strategy/impl/ThirdPartyPushMessageStrategyV1.java

@@ -254,25 +254,27 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
                         .andGhIdEqualTo(bucketDataParam.getGhId());
                 long allCount = cgiReplyBucketDataMapper.countByExample(countExample);
                 if (!CollectionUtils.isEmpty(bucketDataParam.getMiniPageDatas())) {
+                    List<CgiReplyBucketData> existCgiReplyBucketDataList = new ArrayList<>();
                     if (allCount == bucketDataParam.getMiniPageDatas().size()) {
-                        int existNum = 0;
                         for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
                             int sort = i + 1;
                             MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
                             CgiReplyBucketDataExample cgiReplyBucketDataExample = new CgiReplyBucketDataExample();
                             cgiReplyBucketDataExample.createCriteria().andIsDeleteEqualTo(0).andStrategyEqualTo(key)
                                     .andGhIdEqualTo(bucketDataParam.getGhId()).andMiniPagePathEqualTo(miniPageData.getPage()).andSortEqualTo(sort);
-                            long count = cgiReplyBucketDataMapper.countByExample(cgiReplyBucketDataExample);
-                            if (count > 0) {
-                                existNum++;
+                            List<CgiReplyBucketData> list = cgiReplyBucketDataMapper.selectByExample(cgiReplyBucketDataExample);
+                            if (!CollectionUtils.isEmpty(list)) {
+                                existCgiReplyBucketDataList.addAll(list);
                             }
                         }
-                        if (existNum == bucketDataParam.getMiniPageDatas().size()) {
-                            return null;
-                        }
+                        //if (existNum == bucketDataParam.getVideos().size()) {
+                        //    continue;
+                        //}
                     }
+                    Map<Long, VideoDetail> videoDetailMap = touLiuHttpClient.getVideoDetailRequest(bucketDataParam.getVideos());
                     for (int i = 0; i < bucketDataParam.getMiniPageDatas().size(); i++) {
                         int sort = i + 1;
+                        Long videoId = bucketDataParam.getVideos().get(i);
                         MiniPageData miniPageData = bucketDataParam.getMiniPageDatas().get(i);
                         CgiReplyBucketData cgiReplyBucketData = new CgiReplyBucketData();
                         cgiReplyBucketData.setStrategy(key);
@@ -280,11 +282,19 @@ public class ThirdPartyPushMessageStrategyV1 implements ReplyStrategyService {
                         cgiReplyBucketData.setGhId(bucketDataParam.getGhId());
                         cgiReplyBucketData.setMsgType(1);
                         cgiReplyBucketData.setCoverUrl(miniPageData.getCover());
+                        // 替换封面参数
+                        VideoDetail videoDetail = videoDetailMap.get(videoId);
+                        if (videoDetail != null && StringUtils.isNotEmpty(videoDetail.getCover())) {
+                            if (videoDetail.getCover().contains("?")) {
+                                cgiReplyBucketData.setCoverUrl(miniPageData.getCover() + videoDetail.getCover().substring(videoDetail.getCover().indexOf("?")));
+                            }
+                        }
                         cgiReplyBucketData.setTitle(miniPageData.getTitle());
                         cgiReplyBucketData.setMiniPagePath(miniPageData.getPage());
                         cgiReplyBucketData.setMiniAppId(SMALL_APP_Id);
                         result.add(cgiReplyBucketData);
                     }
+                    result = ReplyStrategyService.checkCgiReplyBucketDataDiff(result, existCgiReplyBucketDataList);
                 } else if (!CollectionUtils.isEmpty(bucketDataParam.getVideos())) {
                     List<CgiReplyBucketData> existCgiReplyBucketDataList = new ArrayList<>();
                     if (allCount == bucketDataParam.getVideos().size()) {

+ 0 - 21
api-module/src/main/java/com/tzld/piaoquan/api/service/wecom/impl/ThirdPartyServiceImpl.java

@@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.aliyun.odps.data.Record;
 import com.tzld.piaoquan.api.common.enums.ReplyStrategyServiceEnum;
-import com.tzld.piaoquan.api.dao.mapper.GhDetailExtMapper;
 import com.tzld.piaoquan.api.model.bo.*;
-import com.tzld.piaoquan.api.model.po.GhDetailExt;
-import com.tzld.piaoquan.api.model.po.GhDetailExtExample;
 import com.tzld.piaoquan.api.model.po.contentplatform.ContentPlatformAccount;
 import com.tzld.piaoquan.api.model.vo.PushMessageParam;
 import com.tzld.piaoquan.api.model.vo.PushMessageVo;
@@ -59,9 +56,6 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
     @Autowired
     private GhDetailMapper ghDetailMapper;
 
-    @Autowired
-    private GhDetailExtMapper ghDetailExtMapper;
-
     private static final String canViewReportDate = "2024-10-31";
 
     private Map<String, ReplyStrategyService> strategyServiceMap;
@@ -186,21 +180,6 @@ public class ThirdPartyServiceImpl implements ThirdPartyService {
                 if (StringUtils.isNotEmpty(ghDetail.getVideoIds())) {
                     bucketDataParam.setVideos(JSONArray.parseArray(ghDetail.getVideoIds(), Long.class));
                 }
-                GhDetailExtExample ghDetailExtExample = new GhDetailExtExample();
-                ghDetailExtExample.createCriteria().andGhDetailIdEqualTo(ghDetail.getId()).andIsDeleteEqualTo(0);
-                ghDetailExtExample.setOrderByClause("sort desc, id asc");
-                List<GhDetailExt> ghDetailExts = ghDetailExtMapper.selectByExample(ghDetailExtExample);
-                if (!CollectionUtils.isEmpty(ghDetailExts)) {
-                    List<MiniPageData> miniPageDatas = new ArrayList<>();
-                    for (GhDetailExt ghDetailExt : ghDetailExts) {
-                        MiniPageData miniPageData = new MiniPageData();
-                        miniPageData.setCover(ghDetailExt.getCover());
-                        miniPageData.setPage(ghDetailExt.getPage());
-                        miniPageData.setTitle(ghDetailExt.getTitle());
-                        miniPageDatas.add(miniPageData);
-                    }
-                    bucketDataParam.setMiniPageDatas(miniPageDatas);
-                }
                 return replyStrategyService.getResult(bucketDataParam);
             }
         }

+ 24 - 9
api-module/src/main/resources/mapper/GhDetailExtMapper.xml

@@ -4,6 +4,7 @@
   <resultMap id="BaseResultMap" type="com.tzld.piaoquan.api.model.po.GhDetailExt">
     <id column="id" jdbcType="BIGINT" property="id" />
     <result column="gh_detail_id" jdbcType="BIGINT" property="ghDetailId" />
+    <result column="video_id" jdbcType="BIGINT" property="videoId" />
     <result column="page" jdbcType="VARCHAR" property="page" />
     <result column="title" jdbcType="VARCHAR" property="title" />
     <result column="cover" jdbcType="VARCHAR" property="cover" />
@@ -71,7 +72,7 @@
     </where>
   </sql>
   <sql id="Base_Column_List">
-    id, gh_detail_id, page, title, cover, sort, is_delete, create_time, update_time
+    id, gh_detail_id, video_id, page, title, cover, sort, is_delete, create_time, update_time
   </sql>
   <select id="selectByExample" parameterType="com.tzld.piaoquan.api.model.po.GhDetailExtExample" resultMap="BaseResultMap">
     select
@@ -107,14 +108,14 @@
     </if>
   </delete>
   <insert id="insert" parameterType="com.tzld.piaoquan.api.model.po.GhDetailExt">
-    insert into gh_detail_ext (id, gh_detail_id, page, 
-      title, cover, sort, 
-      is_delete, create_time, update_time
-      )
-    values (#{id,jdbcType=BIGINT}, #{ghDetailId,jdbcType=BIGINT}, #{page,jdbcType=VARCHAR}, 
-      #{title,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, #{sort,jdbcType=INTEGER}, 
-      #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
-      )
+    insert into gh_detail_ext (id, gh_detail_id, video_id, 
+      page, title, cover, 
+      sort, is_delete, create_time, 
+      update_time)
+    values (#{id,jdbcType=BIGINT}, #{ghDetailId,jdbcType=BIGINT}, #{videoId,jdbcType=BIGINT}, 
+      #{page,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, 
+      #{sort,jdbcType=INTEGER}, #{isDelete,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
+      #{updateTime,jdbcType=TIMESTAMP})
   </insert>
   <insert id="insertSelective" parameterType="com.tzld.piaoquan.api.model.po.GhDetailExt">
     insert into gh_detail_ext
@@ -125,6 +126,9 @@
       <if test="ghDetailId != null">
         gh_detail_id,
       </if>
+      <if test="videoId != null">
+        video_id,
+      </if>
       <if test="page != null">
         page,
       </if>
@@ -154,6 +158,9 @@
       <if test="ghDetailId != null">
         #{ghDetailId,jdbcType=BIGINT},
       </if>
+      <if test="videoId != null">
+        #{videoId,jdbcType=BIGINT},
+      </if>
       <if test="page != null">
         #{page,jdbcType=VARCHAR},
       </if>
@@ -192,6 +199,9 @@
       <if test="record.ghDetailId != null">
         gh_detail_id = #{record.ghDetailId,jdbcType=BIGINT},
       </if>
+      <if test="record.videoId != null">
+        video_id = #{record.videoId,jdbcType=BIGINT},
+      </if>
       <if test="record.page != null">
         page = #{record.page,jdbcType=VARCHAR},
       </if>
@@ -222,6 +232,7 @@
     update gh_detail_ext
     set id = #{record.id,jdbcType=BIGINT},
       gh_detail_id = #{record.ghDetailId,jdbcType=BIGINT},
+      video_id = #{record.videoId,jdbcType=BIGINT},
       page = #{record.page,jdbcType=VARCHAR},
       title = #{record.title,jdbcType=VARCHAR},
       cover = #{record.cover,jdbcType=VARCHAR},
@@ -239,6 +250,9 @@
       <if test="ghDetailId != null">
         gh_detail_id = #{ghDetailId,jdbcType=BIGINT},
       </if>
+      <if test="videoId != null">
+        video_id = #{videoId,jdbcType=BIGINT},
+      </if>
       <if test="page != null">
         page = #{page,jdbcType=VARCHAR},
       </if>
@@ -266,6 +280,7 @@
   <update id="updateByPrimaryKey" parameterType="com.tzld.piaoquan.api.model.po.GhDetailExt">
     update gh_detail_ext
     set gh_detail_id = #{ghDetailId,jdbcType=BIGINT},
+      video_id = #{videoId,jdbcType=BIGINT},
       page = #{page,jdbcType=VARCHAR},
       title = #{title,jdbcType=VARCHAR},
       cover = #{cover,jdbcType=VARCHAR},

+ 22 - 0
api-module/src/main/resources/mapper/GhDetailMapperExt.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.tzld.piaoquan.api.dao.mapper.GhDetailMapperExt">
+
+    <insert id="batchInsertGhDetailExt">
+        insert into gh_detail_ext (gh_detail_id, video_id, page, title, cover, sort, is_delete, create_time, update_time)
+        values
+        <foreach collection="records" item="record" separator=",">
+            (#{record.ghDetailId}, #{record.videoId}, #{record.page}, #{record.title}, #{record.cover}, #{record.sort},
+             #{record.isDelete}, #{record.createTime}, #{record.updateTime})
+        </foreach>
+    </insert>
+
+    <update id="deleteOldGhDetailExt">
+        update gh_detail_ext
+        set is_delete = 1
+        where gh_detail_id in (
+            select id from gh_detail where gh_id = #{ghId} and type = #{type}
+        )
+    </update>
+
+</mapper>

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

@@ -27,7 +27,7 @@
         </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"
+                        connectionURL="jdbc:mysql://rm-bp17q95335a99272b.mysql.rds.aliyuncs.com:3306/growth-test?useUnicode=true&amp;characterEncoding=utf-8&amp;zeroDateTimeBehavior=convertToNull&amp;useSSL=false"
                         userId="crawler" password="crawler123456@">
         </jdbcConnection>
 
@@ -35,18 +35,18 @@
             <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">
+        <javaModelGenerator targetPackage="com.tzld.piaoquan.api.model.po" targetProject="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">
+        <sqlMapGenerator targetPackage="mapper" targetProject="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">
+                             targetProject="api-module/src/main/java">
             <property name="enableSubPackages" value="true"/>
         </javaClientGenerator>