فهرست منبع

定时任务同步新创意

xueyiming 2 ماه پیش
والد
کامیت
52cbf2cb0c

+ 2 - 0
src/main/java/com/tzld/piaoquan/featurestools/dao/mapper/CreativeVideoUnderstanderMapper.java

@@ -35,4 +35,6 @@ public interface CreativeVideoUnderstanderMapper {
     int updateByPrimaryKey(CreativeVideoUnderstander record);
 
     List<Integer> selectPriority();
+
+    List<Long> selectNotExistCreativeId();
 }

+ 11 - 0
src/main/java/com/tzld/piaoquan/featurestools/job/CreativeVideoUnderstandJob.java

@@ -34,6 +34,17 @@ public class CreativeVideoUnderstandJob {
     @Autowired
     private VideoUnderstandService videoUnderstandService;
 
+    @XxlJob("addVideoUnderstanderJob")
+    public ReturnT<String> addVideoUnderstander(String param) {
+        List<Long> creativeIdList = creativeVideoUnderstanderMapper.selectNotExistCreativeId();
+        if (!CollectionUtils.isEmpty(creativeIdList)) {
+            for (Long creativeId : creativeIdList) {
+                videoUnderstandService.addCreativeVideoUnderstand(creativeId);
+            }
+        }
+        return ReturnT.SUCCESS;
+    }
+
     @XxlJob("videoUnderstanderJob")
     public ReturnT<String> videoUnderstander(String param) throws InterruptedException {
         if (videoPoolExecutor.getCorePoolSize() - videoPoolExecutor.getActiveCount() > 0) {

+ 2 - 0
src/main/java/com/tzld/piaoquan/featurestools/service/VideoUnderstandService.java

@@ -5,5 +5,7 @@ import com.tzld.piaoquan.featurestools.model.vo.VideoUnderstandResult;
 
 public interface VideoUnderstandService {
 
+    boolean addCreativeVideoUnderstand(Long creativeId);
+
     VideoUnderstandResult getVideoUnderstandResult(VideoUnderstandParam videoUnderstandParam);
 }

+ 25 - 0
src/main/java/com/tzld/piaoquan/featurestools/service/impl/VideoUnderstandServiceImpl.java

@@ -2,12 +2,17 @@ package com.tzld.piaoquan.featurestools.service.impl;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.tzld.piaoquan.featurestools.dao.mapper.CreativeMapper;
+import com.tzld.piaoquan.featurestools.dao.mapper.CreativeVideoUnderstanderMapper;
+import com.tzld.piaoquan.featurestools.model.po.Creative;
+import com.tzld.piaoquan.featurestools.model.po.CreativeVideoUnderstander;
 import com.tzld.piaoquan.featurestools.model.vo.VideoUnderstandParam;
 import com.tzld.piaoquan.featurestools.model.vo.VideoUnderstandResult;
 import com.tzld.piaoquan.featurestools.service.VideoUnderstandService;
 import com.tzld.piaoquan.featurestools.util.HttpClientUtil;
 import com.tzld.piaoquan.featurestools.util.HttpPoolClientUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 @Slf4j
@@ -16,6 +21,26 @@ public class VideoUnderstandServiceImpl implements VideoUnderstandService {
 
     private static final HttpPoolClientUtil httpPoolClientUtil = HttpClientUtil.create(5000, 200000, 10, 20, 3, 3000);
 
+    @Autowired
+    private CreativeMapper creativeMapper;
+
+    @Autowired
+    private CreativeVideoUnderstanderMapper creativeVideoUnderstanderMapper;
+
+    @Override
+    public boolean addCreativeVideoUnderstand(Long creativeId) {
+        try {
+            Creative creative = creativeMapper.selectByPrimaryKey(creativeId);
+            CreativeVideoUnderstander creativeVideoUnderstander = new CreativeVideoUnderstander();
+            creativeVideoUnderstander.setCreativeId(creativeId);
+            creativeVideoUnderstander.setVideoUrl(creative.getMaterialAddress());
+            int i = creativeVideoUnderstanderMapper.insertSelective(creativeVideoUnderstander);
+            return i > 0;
+        } catch (Exception e) {
+            log.error("addCreativeVideoUnderstand error", e);
+        }
+        return false;
+    }
 
     @Override
     public VideoUnderstandResult getVideoUnderstandResult(VideoUnderstandParam videoUnderstandParam) {

+ 7 - 0
src/main/resources/mapper/CreativeVideoUnderstanderMapper.xml

@@ -387,4 +387,11 @@
     where status = 0
     order by priority desc
   </select>
+
+
+  <select id="selectNotExistCreativeId"  resultType="java.lang.Long">
+    SELECT id
+    FROM creative
+    WHERE id NOT IN (SELECT creative_id FROM creative_video_understander)
+  </select>
 </mapper>