yumeng %!s(int64=4) %!d(string=hai) anos
pai
achega
610ed17a71

+ 5 - 46
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/controller/KuaiShouMaterialControer.java

@@ -5,7 +5,6 @@ import cn.com.ctop.common.module.service.ICtopOauthTokenService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
-import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouVideoGetService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouVideoRelateCreativesService;
@@ -94,8 +93,6 @@ public class KuaiShouMaterialControer {
                 throw new Exception("未获取账号授权信息");
             }
             String appVersion = requestJson.getString("appVersion");
-            // String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
-            //  iKuaishouInterfaceService.getVideoList(token, nowDate, nowDate);
             KuaiShouVideoLastTime videoLastTime = lastTimeService.getById(accountId);
             Date startTime;
             Date endDate = new Date();
@@ -186,20 +183,7 @@ public class KuaiShouMaterialControer {
             }
             List<JSONObject> materialList = relateCreativesService.getVideoListByMap(requestMap);
             if (!Check.isNull(materialList)) {
-                for (int i = 0; i < materialList.size(); i++) {
-                    JSONObject materialJson = materialList.get(i);
-                    KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(materialJson.getLong("photo_id"));
-                    if (!Check.isNull(videoGet)) {
-                        String signature = videoGet.getSignature();
-                        materialJson.put("signature", signature);
-                        materialJson.put("video_url", videoGet.getUrl());
-                        materialJson.put("material_type", videoGet.getMaterialType());
-                        materialJson.put("channel_type", videoGet.getChannelType());
-                        materialJson.put("photo_name", videoGet.getPhotoName());
-                        List<String> imageList = lastTimeService.getImageListByMd5(signature);
-                        materialJson.put("imageList", imageList);
-                    }
-                }
+                materialList = videoGetService.getVideoInfoAndImageList(materialList);
                 returnJson.put("code", 0);
                 returnJson.put("message", "SUCCESS");
                 returnJson.put("data", materialList);
@@ -224,7 +208,7 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getHistoryTopVideoList")
     public JSONObject getHistoryTopVideoList(@RequestBody JSONObject requestJson) {
-      //   log.info("获取历史Top素材入参:{}", requestJson);
+        //   log.info("获取历史Top素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {
@@ -257,19 +241,7 @@ public class KuaiShouMaterialControer {
             }
             List<JSONObject> materialList = relateCreativesService.getHistoryTopVideoList(requestMap);
             if (!Check.isNull(materialList)) {
-                for (int i = 0; i < materialList.size(); i++) {
-                    JSONObject materialJson = materialList.get(i);
-                    KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(materialJson.getLong("photo_id"));
-                    if (!Check.isNull(videoGet)) {
-                        String signature = videoGet.getSignature();
-                        materialJson.put("video_url", videoGet.getUrl());
-                        materialJson.put("material_type", videoGet.getMaterialType());
-                        materialJson.put("channel_type", videoGet.getChannelType());
-                        materialJson.put("photo_name", videoGet.getPhotoName());
-                        List<String> imageList = lastTimeService.getImageListByMd5(signature);
-                        materialJson.put("imageList", imageList);
-                    }
-                }
+                materialList = videoGetService.getVideoInfoAndImageList(materialList);
                 returnJson.put("code", 0);
                 returnJson.put("message", "SUCCESS");
                 returnJson.put("data", materialList);
@@ -294,7 +266,7 @@ public class KuaiShouMaterialControer {
      */
     @PostMapping(value = "/getCreateZeroVideoList")
     public JSONObject getHistoryCreateVideoList(@RequestBody JSONObject requestJson) {
-      //  log.info("获取关联创意数为0素材入参:{}", requestJson);
+        //  log.info("获取关联创意数为0素材入参:{}", requestJson);
         JSONObject returnJson = new JSONObject();
         try {
             if (Check.isNull(requestJson)) {
@@ -328,20 +300,7 @@ public class KuaiShouMaterialControer {
             }
             List<JSONObject> materialList = relateCreativesService.getVideoZeroListByMap(requestMap);
             if (!Check.isNull(materialList)) {
-                for (int i = 0; i < materialList.size(); i++) {
-                    JSONObject materialJson = materialList.get(i);
-                    KuaiShouVideoGet videoGet = videoGetService.getVideoByPhotoId(materialJson.getLong("photo_id"));
-                    if (!Check.isNull(videoGet)) {
-                        String signature = videoGet.getSignature();
-                        materialJson.put("signature", signature);
-                        materialJson.put("video_url", videoGet.getUrl());
-                        materialJson.put("channel_type", videoGet.getChannelType());
-                        materialJson.put("material_type", videoGet.getMaterialType());
-                        materialJson.put("photo_name", videoGet.getPhotoName());
-                        List<String> imageList = lastTimeService.getImageListByMd5(signature);
-                        materialJson.put("imageList", imageList);
-                    }
-                }
+                materialList = videoGetService.getVideoInfoAndImageList(materialList);
                 returnJson.put("code", 0);
                 returnJson.put("message", "SUCCESS");
                 returnJson.put("data", materialList);

+ 4 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/KuaiShouVideoLastTimeMapper.java

@@ -1,7 +1,9 @@
 package cn.com.ctop.kuaishou.modules.ai.mapper;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -15,4 +17,6 @@ import java.util.List;
 public interface KuaiShouVideoLastTimeMapper extends BaseMapper<KuaiShouVideoLastTime> {
 
     List<String> getImageListByMd5(String signature);
+
+    List<JSONObject> getImageListByMd5List(@Param("codeList") List<String> videoCodeList);
 }

+ 12 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/mapper/xml/KuaiShouVideoLastTimeMapper.xml

@@ -9,4 +9,16 @@
       limit 15
     </select>
 
+    <select id="getImageListByMd5List" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        video_signature,
+        signature
+        from ctop_material_cut_frame t1
+        where t1.video_signature in
+        <foreach collection="codeList" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+    </select>
+
 </mapper>

+ 3 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/IKuaiShouVideoLastTimeService.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.ai.service;
 
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.util.List;
@@ -14,4 +15,6 @@ import java.util.List;
 public interface IKuaiShouVideoLastTimeService extends IService<KuaiShouVideoLastTime> {
 
     List<String> getImageListByMd5(String signature);
+
+    List<JSONObject> getImageListByMd5List(List<String> videoCodeList);
 }

+ 6 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/ai/service/impl/KuaiShouVideoLastTimeServiceImpl.java

@@ -3,6 +3,7 @@ package cn.com.ctop.kuaishou.modules.ai.service.impl;
 import cn.com.ctop.kuaishou.modules.ai.entity.KuaiShouVideoLastTime;
 import cn.com.ctop.kuaishou.modules.ai.mapper.KuaiShouVideoLastTimeMapper;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -25,4 +26,9 @@ public class KuaiShouVideoLastTimeServiceImpl extends ServiceImpl<KuaiShouVideoL
     public List<String> getImageListByMd5(String signature) {
         return videoLastTimeMapper.getImageListByMd5(signature);
     }
+
+    @Override
+    public List<JSONObject> getImageListByMd5List(List<String> videoCodeList) {
+        return videoLastTimeMapper.getImageListByMd5List(videoCodeList);
+    }
 }

+ 2 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/KuaiShouVideoGetMapper.java

@@ -30,4 +30,6 @@ public interface KuaiShouVideoGetMapper extends BaseMapper<KuaiShouVideoGet> {
     List<KuaiShouVideoGet> getPhotoIdsByParams(Long accountId, String signature);
 
     void etlVideoBaseInfoByStaDate(@Param("statDate") String statDate);
+
+    List<JSONObject> getVideoInfoByPhotoIds(@Param("photoIdList") List<Long> photoIdList);
 }

+ 17 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaiShouVideoGetMapper.xml

@@ -146,4 +146,21 @@
 	photo_id
  </insert>
 
+    <select id="getVideoInfoByPhotoIds" resultType="com.alibaba.fastjson.JSONObject">
+        select
+        photo_id as 'photoId',
+        signature as 'signature',
+        channel_type as 'channelType',
+        photo_name as 'photoName',
+        material_type as 'materialType'
+        from ctop_etl_kuaishou_video_base_info
+        where photo_id in
+        <foreach collection="photoIdList" item="item" separator=","
+                 open="(" close=")">
+            #{item}
+        </foreach>
+        and signature is not null
+        group by photo_id
+    </select>
+
 </mapper>

+ 0 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/mapper/xml/KuaishouVideoRelateCreativesMapper.xml

@@ -83,7 +83,6 @@
     <select id="getHistoryTopVideoList" resultType="com.alibaba.fastjson.JSONObject">
         select
         t2.photo_id,
-        t1.signature,
         t1.charge
         FROM
         (

+ 5 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/IKuaiShouVideoGetService.java

@@ -5,7 +5,6 @@ import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
 
-import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -17,7 +16,6 @@ import java.util.Map;
  */
 
 
-
 public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     void replaceBatch(List<KuaiShouVideoGet> videoGets);
 
@@ -25,11 +23,11 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
 
     List<KuaiShouVideoGetVo> getVideoList(Map<String, Object> stringObjectMap);
 
-    List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId,Integer videoAiStatus);
+    List<KuaiShouVideoGet> getNewVideoByAccountId(Long accountId, Integer videoAiStatus);
 
-    List<KuaiShouVideoGet> getNewVideoDescDate(Long accountId,Integer newVideoCnt);
+    List<KuaiShouVideoGet> getNewVideoDescDate(Long accountId, Integer newVideoCnt);
 
-    List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId,String startTime, String endTime);
+    List<KuaiShouVideoGet> getNewVideoBetweenTime(Long accountId, String startTime, String endTime);
 
     List<JSONObject> getVideoListByMap(Map<String, Object> requestMap);
 
@@ -38,4 +36,6 @@ public interface IKuaiShouVideoGetService extends IService<KuaiShouVideoGet> {
     KuaiShouVideoGet getVideoByPhotoId(Long photo_id);
 
     void etlVideoBaseInfoByStaDate(String statDate);
+
+    List<JSONObject> getVideoInfoAndImageList(List<JSONObject> materialList);
 }

+ 57 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaiShouVideoGetServiceImpl.java

@@ -5,6 +5,7 @@ import cn.com.ctop.common.module.service.IMaterialCutFrameService;
 import cn.com.ctop.common.module.utils.Check;
 import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
+import cn.com.ctop.kuaishou.modules.ai.service.IKuaiShouVideoLastTimeService;
 import cn.com.ctop.kuaishou.modules.batch.entity.KuaiShouVideoGet;
 import cn.com.ctop.kuaishou.modules.batch.entity.vo.KuaiShouVideoGetVo;
 import cn.com.ctop.kuaishou.modules.batch.mapper.KuaiShouVideoGetMapper;
@@ -19,7 +20,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
-import java.util.Date;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -40,6 +41,9 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
     @Value("${oss.replace.download}")
     private String downloadUrl;
 
+    @Autowired
+    private IKuaiShouVideoLastTimeService lastTimeService;
+
     @Override
     public void replaceBatch(List<KuaiShouVideoGet> videoGets) {
         videoGetMapper.replaceBatch(videoGets);
@@ -183,4 +187,56 @@ public class KuaiShouVideoGetServiceImpl extends ServiceImpl<KuaiShouVideoGetMap
         videoGetMapper.etlVideoBaseInfoByStaDate(statDate);
     }
 
+    @Override
+    public List<JSONObject> getVideoInfoAndImageList(List<JSONObject> materialList) {
+        List<Long> photoIdList = new ArrayList();
+        for (int i = 0; i < materialList.size(); i++) {
+            JSONObject materialJson = materialList.get(i);
+            photoIdList.add(materialJson.getLong("photo_id"));
+        }
+        Map<Long, JSONObject> materialMap = new HashMap<>();
+        List<String> videoCodeList = new ArrayList<>();
+
+        List<JSONObject> videoList = videoGetMapper.getVideoInfoByPhotoIds(photoIdList);
+        Map<String, List<String>> imageMap = new HashMap<>();
+        for (int i = 0; i < videoList.size(); i++) {
+            JSONObject jsonObject = videoList.get(i);
+            materialMap.put(jsonObject.getLong("photoId"), jsonObject);
+            videoCodeList.add(jsonObject.getString("signature"));
+            imageMap.put(jsonObject.getString("signature"), new ArrayList<>());
+        }
+        imageMap = this.getImageListByMd5(videoCodeList, imageMap);
+        for (int i = 0; i < materialList.size(); i++) {
+            JSONObject materialJson = materialList.get(i);
+            Long photoId = materialJson.getLong("photo_id");
+            JSONObject jsonObject = materialMap.get(photoId);
+            if (Check.isNull(jsonObject)) {
+                continue;
+            }
+            String signature = jsonObject.getString("signature");
+            materialJson.put("signature", signature);
+            materialJson.put("material_type", jsonObject.getString("materialType"));
+            materialJson.put("channel_type", jsonObject.getString("channelType"));
+            materialJson.put("photo_name", jsonObject.getString("photoName"));
+            List<String> imageList = imageMap.get(signature);
+            materialJson.put("imageList", imageList);
+        }
+        return materialList;
+    }
+
+    private Map<String, List<String>> getImageListByMd5(List<String> videoCodeList, Map<String, List<String>> imageMap) {
+        List<JSONObject> imageList = lastTimeService.getImageListByMd5List(videoCodeList);
+        for (int i = 0; i < imageList.size(); i++) {
+            JSONObject jsonObject = imageList.get(i);
+            if (Check.isNull(jsonObject)) {
+                continue;
+            }
+            String video_signature = jsonObject.getString("video_signature");
+            List<String> jsonObjects = imageMap.get(video_signature);
+            jsonObjects.add(jsonObject.getString("signature"));
+        }
+        return imageMap;
+    }
+
+
 }