yangzian 3 anni fa
parent
commit
828ab02564

+ 21 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/ByteDanceVideoInfoMapper.java

@@ -48,6 +48,27 @@ public interface ByteDanceVideoInfoMapper extends BaseMapper<ByteDanceVideoInfo>
     List<ByteDanceVideoInfo>imageHistoryMatByParams(@Param(value = "projectId")Long projectId, @Param(value = "accountId")Long accountId, @Param(value = "imageMode") String imageMode,@Param(value = "startTime")String startTime, @Param(value = "endTime")String endTime, @Param(value = "videoCnt")Long videoCnt,@Param(value = "now") String now);
 
 
+    /**
+     * 通投智选 - 横版视频
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @param videoCnt
+     * @return
+     */
+    List<ByteDanceVideoInfo> getModeVideo(@Param(value = "accountId") Long accountId,@Param(value = "startTime")String startTime, @Param(value = "endTime")String endTime, @Param(value = "videoCnt")Long videoCnt);
+
+    /**
+     * 通投智选 - 横图大图
+     * @param accountId
+     * @param startTime
+     * @param endTime
+     * @param videoCnt
+     * @return
+     */
+    List<ByteDanceVideoInfo> getModeImageLarge(@Param(value = "accountId") Long accountId,@Param(value = "startTime")String startTime, @Param(value = "endTime")String endTime, @Param(value = "videoCnt")Long videoCnt);
+
+
 
 
 }

+ 39 - 0
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/mapper/xml/ByteDanceVideoInfoMapper.xml

@@ -269,4 +269,43 @@
     </select>
 
 
+
+
+<!-- 通投智选 - 横版视频 -->
+    <select id="getModeVideo" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo">
+        select distinct video.*,
+        (select count(1) from ctop_bytedance_creative c where c.video_id = video.vid and c.account_id = '${accountId}') as creativeCnt,
+        'video' As materialType
+        from ctop_bytedance_video_info video
+        left join ctop_material_info cmi on video.signature = cmi.code
+        where account_id = #{accountId}
+        and cmi.code is not null
+        and cmi.status = 1
+        and cmi.offline_flag = 0
+        and video.status = 1
+        and video.type = 1
+        and material_upload_time  &gt;= #{startTime}
+        and material_upload_time &lt;= #{endTime}
+        order by creativeCnt ASC
+        limit #{videoCnt}
+    </select>
+
+    <!-- 通投智选 - 横图大图 -->
+    <select id="getModeImageLarge" resultType="org.jeecg.modules.bytedance.advertise.entity.ByteDanceVideoInfo">
+        select distinct image.*,
+        (select count(1) from ctop_bytedance_creative c
+        where SUBSTRING_INDEX(SUBSTRING_INDEX(image_ids,'["',-1),'"]',1) in(image.id)
+        and c.account_id = '${accountId}') as creativeCnt,
+        'image' as materialType
+        from ctop_bytedance_image_info image
+        where account_id = #{accountId}
+        and image.type = '1'
+        and image.image_create_time &gt;= #{startTime}
+        and image.image_create_time &lt;= #{endTime}
+        order by  creativeCnt ASC
+        limit #{videoCnt}
+    </select>
+
+
+
 </mapper>

+ 60 - 11
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/advertise/service/impl/AiBytedanceAdvertiserStrategyServiceImpl.java

@@ -27,6 +27,7 @@ import org.jeecg.modules.bytedance.common.service.*;
 import org.jeecg.modules.bytedance.common.utils.Check;
 import org.jeecg.modules.bytedance.common.utils.GetCampaignNum;
 import org.jeecg.modules.bytedance.common.utils.StringUtils;
+import org.jeecg.modules.bytedance.report.utils.TimeStartAndEndUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -103,7 +104,7 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
         //获取素材 账户所在的项目id 为空
         List<ByteDanceVideoInfo> videoInfos = getvideoOrImageInfoByCreateType(null,strategy,startTime,endTime,createType,videoCnt);
         if(null == videoInfos||videoInfos.isEmpty()){
-            log.info("获取{}视频素材为空=>accountId:{}",BytedanceCreativeMatTypeEnum.getNameByType(createType+""),token.getAccountId());
+            log.info("获取{}素材为空=>accountId:{}",BytedanceCreativeMatTypeEnum.getNameByType(createType+""),token.getAccountId());
             return videoCnt;
         }
         log.info("获取{}素材个数:{}=>accountId:{}",BytedanceCreativeMatTypeEnum.getNameByType(createType+""),videoInfos.size(),token.getAccountId());
@@ -416,11 +417,8 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                     }
                     JSONObject titleObject = new JSONObject();
                     titleObject.put("title",byteDanceGeneralCopywriter.get(i).getTextCopywriter());
-
                     String creativeWordsIds = byteDanceGeneralCopywriter.get(i).getCreativeWordIds();
-
                     JSONArray wordsArr = new JSONArray();
-
                     if(null != creativeWordsIds && !creativeWordsIds.trim().equals("")){
                         JSONArray creativeWordsArray = JSON.parseArray(creativeWordsIds);
                             for (Object creative : creativeWordsArray) {
@@ -429,7 +427,6 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                                 wordsArr.add(creativeObject);
                             }
                             titleObject.put("word_list",wordsArr);
-
                     }
                     titleArray.add(titleObject);
                 }
@@ -457,7 +454,6 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
                     }
                     titleArray.add(titleObject);
                 }
-
             }
         }
         if (Check.isNull(titleArray)){
@@ -471,11 +467,9 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
             iBytedanceAutocreateLogService.save(iBytedanceAutocreateLog);
         }
         creObj.put("title_materials",titleArray);
-
         JSONArray imageMaterials = new JSONArray();
         JSONObject object = new JSONObject();
         //类型
-
         if ("image".equalsIgnoreCase(videoInfo.getMaterialType())){
             //图片素材
             object.put("image_mode",strategy.getCreativeImageMode());
@@ -505,12 +499,60 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
             }
             object.put("image_info",imgObj);
             object.put("video_info",videoObj);
-
             imageMaterials.add(object);
-
             creObj.put("video_materials",imageMaterials);
         }
 
+        //通投智选 竖版视频 横版视频 横图大图
+        if (!Check.isNull(strategy.getAdDeliveryRange()) && "UNIVERSAL".equalsIgnoreCase(strategy.getAdDeliveryRange())){
+            List<ByteDanceVideoInfo> resultList = new ArrayList<>();
+            //获取 最近14天的时间 开始 和截至时间点
+            Map<String,String> map = TimeStartAndEndUtil.getNowFourTeenTime();
+            //横板视频
+            if (strategy.getCreativeImageMode().contains("CREATIVE_IMAGE_MODE_VIDEO")){
+                List<ByteDanceVideoInfo>  listMode = byteDanceVideoInfoMapper.getModeVideo(strategy.getAccountId(),map.get("startTime"),map.get("endTime"),1L);
+                if (!Check.isNull(listMode)){
+                    for (ByteDanceVideoInfo info : listMode) {
+                        //横板视频
+                        object.put("image_mode","CREATIVE_IMAGE_MODE_VIDEO");
+                        JSONObject videoObj = new JSONObject();
+                        videoObj.put("video_id",info.getVid());
+                        //视频封面
+                        JSONObject imgObj = new JSONObject();
+                        //获取视频封面id
+                        String imageId = getSuggestImageId(token,info.getVid());
+                        if(!Check.isNull(imageId)){
+                            imgObj.put("image_id",imageId);
+                        }
+                        object.put("image_info",imgObj);
+                        object.put("video_info",videoObj);
+                        imageMaterials.add(object);
+                        creObj.put("video_materials",imageMaterials);
+                    }
+                }
+            }
+            //横图大图
+            if (strategy.getCreativeImageMode().contains("CREATIVE_IMAGE_MODE_LARGE")){
+                List<ByteDanceVideoInfo>  listImage = byteDanceVideoInfoMapper.getModeImageLarge(strategy.getAccountId(),map.get("startTime"),map.get("endTime"),1L);
+                if (!Check.isNull(listImage)){
+                    for (ByteDanceVideoInfo info : listImage) {
+                        //图片素材
+                        object.put("image_mode","CREATIVE_IMAGE_MODE_LARGE");
+                        String[] imageIds = new String[]{info.getId()};
+                        JSONArray image_info = new JSONArray();
+                        for (String imgId : imageIds) {
+                            JSONObject imageObject = new JSONObject();
+                            imageObject.put("image_id",imgId);
+                            image_info.add(imageObject);
+                        }
+                        object.put("image_info",image_info);
+                        imageMaterials.add(object);
+                        creObj.put("image_materials",imageMaterials);
+                    }
+                }
+            }
+        }
+
         //副标题
         String subTitle = strategy.getCreativeSubTitle();
         if(!Check.isNull(subTitle)){
@@ -530,7 +572,6 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
            }
            creObj.put("component_materials",component);
        }
-
         params.put("creative",creObj);
         return params;
 
@@ -1209,7 +1250,15 @@ public class AiBytedanceAdvertiserStrategyServiceImpl extends ServiceImpl<AiByte
         return null;
     }
 
+    @Resource
+    private ByteDanceVideoInfoMapper byteDanceVideoInfoMapper;
+
     private List<ByteDanceVideoInfo> getvideoOrImageInfoByCreateType(Long projectId,AiBytedanceAdvertiserStrategy strategy, String startTime, String endTime, Integer createType, Long videoCnt) {
+        //通投智选 (以 竖版视频 类型为主)
+        if (!Check.isNull(strategy.getAdDeliveryRange()) && "UNIVERSAL".equalsIgnoreCase(strategy.getAdDeliveryRange())){
+            strategy.setCreativeImageMode("CREATIVE_IMAGE_MODE_VIDEO_VERTICAL");
+            return getVideoInfoByCreateType(projectId,strategy,startTime,endTime,createType,videoCnt);
+        }
         //横板视频 || 竖版视频
         if (strategy.getCreativeImageMode().equalsIgnoreCase("CREATIVE_IMAGE_MODE_VIDEO")
                 || strategy.getCreativeImageMode().equalsIgnoreCase("CREATIVE_IMAGE_MODE_VIDEO_VERTICAL")){

+ 19 - 2
jeecg-boot-bytedance/src/main/java/org/jeecg/modules/bytedance/report/utils/TimeStartAndEndUtil.java

@@ -81,11 +81,28 @@ public class TimeStartAndEndUtil {
     }
 
 
+    /**
+     * 获取当前时间 -14 天的时间点
+     * @param
+     * @return
+     */
+    public static Map<String,String> getNowFourTeenTime(){
+        Map map = new HashMap();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar cld = Calendar.getInstance();
+        cld.setTime(new Date());
+        cld.set(Calendar.DATE, cld.get(Calendar.DATE) - 14);
+        map.put("startTime",sdf.format(cld.getTime()) +" 00:00:00");
+        map.put("endTime",sdf.format(new Date()) +" 23:59:59");
+        return map;
+    }
+
 
     public static void main(String[] args) throws Exception {
 //        Map<String,String> map = TimeStartAndEndUtil.getStartEndTime("2020-05-15","2020-05-18");
-        List<String> list = TimeStartAndEndUtil.getAllDatesOfTwoTimes("2021-05-19","2021-05-27");
-        System.out.println(list);
+        //List<String> list = TimeStartAndEndUtil.getAllDatesOfTwoTimes("2021-05-19","2021-05-27");
+
+        System.out.println(getNowFourTeenTime());
     }