Kaynağa Gözat

伊对报表计划数据获取

syh 5 yıl önce
ebeveyn
işleme
344928e7f9

+ 4 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/IFfmpegService.java

@@ -0,0 +1,4 @@
+package org.jeecg.modules.ctop.service;
+
+public interface IFfmpegService {
+}

+ 140 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/FfmpegServiceImpl.java

@@ -0,0 +1,140 @@
+package org.jeecg.modules.ctop.service.impl;
+
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.modules.ctop.service.IFfmpegService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+@Slf4j
+public class FfmpegServiceImpl implements IFfmpegService {
+    /**
+     * FFmpeg全路径
+     */
+    @Value("${jeecg.ffmpeg.bin}")
+    private String FFMPEG_PATH;
+
+    /**
+     * 从视频中抽取音频文件
+     */
+    public void getM4aFromMp4(String videoPath, String m4apath) {
+        /**
+         * D:\java\ffmpeg\bin\ffmpeg.exe -i D:\data\test\\video.mp4 -vn -y -acodec copy D:\data\test\\video.m4a
+         */
+        List<String> command = new ArrayList<>();
+        command.add(FFMPEG_PATH);
+        command.add("-i");
+        command.add(videoPath);
+        command.add("-vn");
+        command.add("-y");
+        command.add("-acodec");
+        command.add("copy");
+        command.add(m4apath);
+        runCommand(command);
+    }
+
+    /**
+     * 截取音频文件
+     */
+    public void cutM4a(String srcPath, String targetPath, String startSecond, String endSecond) {
+        /**
+         *D:\java\ffmpeg\bin\ffmpeg.exe -i D:\data\test\\video.m4a -vn -acodec copy -ss 00:00:00.000 -t 00:00:08.000 D:\data\test\\cut.m4a
+         */
+        List<String> command = new ArrayList<>();
+        command.add(FFMPEG_PATH);
+        command.add("-i");
+        command.add(srcPath);
+        command.add("-vn");
+        command.add("-acodec");
+        command.add("copy");
+        command.add("-ss");
+        command.add(startSecond);
+        command.add("-t");
+        command.add(endSecond);
+        command.add(targetPath);
+        runCommand(command);
+    }
+
+    /**
+     * 音频拼接
+     * D:\java\ffmpeg\bin\ffmpeg.exe -i D:\data\test\\cut.m4a -i D:\data\test\\fill.m4a -filter_complex "[0:0] [1:0] concat=n=2:v=0:a=1 [a]" -map [a] D:\data\test\\final.m4a
+     */
+    public void audioMosaic(String audioPart1, String audioPart2, String finalAudio) {
+        List<String> command = new ArrayList<>();
+        command.add(FFMPEG_PATH);
+        command.add("-i");
+        command.add(audioPart1);
+        command.add("-i");
+        command.add(audioPart2);
+        command.add("-filter_complex");
+        command.add("\"[0:0] [1:0] concat=n=2:v=0:a=1 [a]\"");
+        command.add("-map");
+        command.add("[a]");
+        command.add(finalAudio);
+        runCommand(command);
+    }
+
+    /**
+     * 音频+视频合成视频
+     *
+     * @param srcVideoPath
+     * @param srcAudioPath
+     * @param finalVideoPath D:\java\ffmpeg\bin\ffmpeg.exe -i D:\data\test\\merge.mp4 -i D:\data\test\\final.m4a -c:v copy -c:a aac -strict experimental D:\data\test\\final.mp4
+     */
+    public void mergeAudioAndVideo(String srcVideoPath, String srcAudioPath, String finalVideoPath) {
+        List<String> command = new ArrayList<>();
+        command.add(FFMPEG_PATH);
+        command.add("-i");
+        command.add(srcVideoPath);
+        command.add("-i");
+        command.add(srcAudioPath);
+        command.add("-c:v");
+        command.add("copy");
+        command.add("-c:a");
+        command.add("aac");
+        command.add("-strict");
+        command.add("experimental");
+        command.add(finalVideoPath);
+        runCommand(command);
+    }
+
+    /**
+     * D:\java\ffmpeg\bin\ffmpeg.exe -f image2 -i D:\\data\\video\\%d.jpg  -vcodec libx264 -r 25  D:\\data\\merge.mp4
+     *
+     * @param imagePath
+     * @param frameNumber
+     * @param videoFilePath
+     */
+    public void MergeImageToVideo(String imagePath, Integer frameNumber, String videoFilePath) {
+        List<String> command = new ArrayList<>();
+        command.add(FFMPEG_PATH);
+        command.add("-i");
+        command.add("image2");
+        command.add("-i");
+        command.add(imagePath + "%d.jpg");
+        command.add("-vcodec");
+        command.add("copy");
+        command.add("libx264");
+        command.add("-r");
+        command.add(frameNumber + "");
+        command.add(videoFilePath);
+        runCommand(command);
+    }
+
+    private void runCommand(List<String> command) {
+        try {
+            ProcessBuilder builder = new ProcessBuilder();
+            builder.command(command);
+            builder.redirectErrorStream(true);
+            Process process = builder.start();
+            // 等待进程执行结束
+            process.waitFor();
+            log.info("ffmpeg命令执行完成");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}

+ 2 - 2
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/PerformanceSaleServiceImpl.java

@@ -55,7 +55,7 @@ public class PerformanceSaleServiceImpl implements IPerformanceSaleService {
 
     public void countPerformance(SysUser user) {
 //        Date getDate = DateUtils.addDay(new Date(), -1)
-        Date getDate = DateUtils.addDay(new Date(), -5);
+        Date getDate = DateUtils.addDay(new Date(), -15);
         String startDateStr = DateUtils.getQuarterStartDate(getDate);
         String endDateStr = DateUtils.getQuarterEndDate(getDate);
         //获取用户角色信息
@@ -153,7 +153,7 @@ public class PerformanceSaleServiceImpl implements IPerformanceSaleService {
     }
 
     private BigDecimal getPercentagePercent(SalePerformanceDetail detail) {
-        BigDecimal percent = detail.getDoMediaTask().divide(detail.getMediaTask()).multiply(new BigDecimal("100"));
+        BigDecimal percent = detail.getDoMediaTask().divide(detail.getMediaTask(), 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
         //AM非自拓客户
         if (detail.getRoleId().equals(CtopAdConstant.SYSTEM_SALE_AM_CODE) && detail.getExtensionSelf() != 1) {
             return new BigDecimal("0.0005");

+ 0 - 141
jeecg-boot-module-system/src/main/java/org/jeecg/modules/demo/opencv/FFmpegUtils.java

@@ -1,141 +0,0 @@
-//package org.jeecg.modules.demo.opencv;
-//
-//import java.io.BufferedReader;
-//import java.io.IOException;
-//import java.io.InputStream;
-//import java.io.InputStreamReader;
-//import java.text.SimpleDateFormat;
-//import java.util.ArrayList;
-//import java.util.Date;
-//import java.util.List;
-//import java.util.UUID;
-//
-//public class FFmpegUtils {
-//    public static void videoToPcm(String vedioUrl,String m4aUrl,String ffmpegUrl) throws InterruptedException, IOException {
-//        List<String> commend = new ArrayList<String>();
-//        commend.add(ffmpegUrl);
-//        commend.add("-i");
-//        commend.add(vedioUrl);
-//        commend.add("-vn");
-//        commend.add("y");
-//        commend.add("-acodec");
-//        commend.add("copy");
-//        commend.add(m4aUrl);
-//        ProcessBuilder builder = new ProcessBuilder();
-//        builder.command(commend);
-//        builder.redirectErrorStream(true);
-//        Process process = builder.start();
-//        process.waitFor();// 等待进程执行结束
-//    }
-//
-//    public static void mergeVideodioAndPcm(String videoInputPath, String audioInputPath, String videoOutPath,String ffmpegUrl) throws InterruptedException, IOException {
-//        /**
-//         *  String command = FFMPEG_PATH + " -i " + videoInputPath + " -i " + audioInputPath
-//         *   + " -c:v copy -c:a aac -strict experimental " +
-//         *   " -map 0:v:0 -map 1:a:0 "
-//         *   + " -y " + videoOutPath;
-//         */
-//        List<String> commend = new ArrayList<String>();
-//        commend.add(ffmpegUrl);
-//        commend.add("-i");
-//        commend.add(videoInputPath);
-//        commend.add("-i");
-//        commend.add(audioInputPath);
-//        commend.add(" -c:v");
-//        commend.add("copy");
-//        commend.add("-c:a");
-//        commend.add("acc");
-//        commend.add("-strict");
-//        commend.add("experimental");
-//        commend.add(videoOutPath);
-//        ProcessBuilder builder = new ProcessBuilder();
-//        builder.command(commend);
-//        builder.redirectErrorStream(true);
-//        Process process = builder.start();
-//        process.waitFor();// 等待进程执行结束
-//    }
-//
-//    public static void main(String[] args) throws InterruptedException, IOException {
-////        videoToPcm("D:\\data\\fill.mp4","D:\\data\\fill.m4a","D:\\java\\ffmpeg\\bin\\ffmpeg.exe");
-////        mergeVideodioAndPcm("D:\\data\\merge.mp4","D:\\data\\fill.m4a","D:\\data\\fill2.mp4","D:\\java\\ffmpeg\\bin\\ffmpeg.exe");
-//        try {
-//			videoToAudio("D:\\data\\test\\fill.mp4","D:\\data\\test\\123.mp3");
-//            String videoInputPath = "D:\\data\\test\\merge.mp4";
-//            String audioInputPath = "D:\\data\\test\\123.mp3";
-//            String videoOutPath = "D:\\data\\test\\fill.mp4";
-//            convetor(videoInputPath,audioInputPath,videoOutPath);
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//        System.out.println("---------获取音频文件成功!-----------");
-//    }
-//
-//    /**
-//     * @param videoInputPath 原视频的全路径
-//     * @param audioInputPath 音频的全路径
-//     * @param videoOutPath   视频与音频结合之后的视频的路径
-//     * @throws Exception
-//     */
-//    public static void convetor(String videoInputPath, String audioInputPath, String videoOutPath)
-//            throws Exception {
-//        Process process = null;
-//        try {
-//            String command =FFMPEG_PATH + " -i " + videoInputPath + " -i " + audioInputPath + " -c:v copy -c:a aac -strict experimental " +
-//                    " -map 0:v:0 -map 1:a:0 "
-//                    + " -y " + videoOutPath;
-//            System.out.println(command);
-//            process = Runtime.getRuntime().exec(command);
-//            process.waitFor();
-//        } catch (IOException e) {
-//            // TODO Auto-generated catch block
-//            e.printStackTrace();
-//        }
-//        // 使用这种方式会在瞬间大量消耗CPU和内存等系统资源,所以这里我们需要对流进行处理
-//        InputStream errorStream = process.getErrorStream();
-//        InputStreamReader inputStreamReader = new InputStreamReader(errorStream);
-//        BufferedReader br = new BufferedReader(inputStreamReader);
-//
-//        String line = "";
-//        while ((line = br.readLine()) != null) {
-//        }
-//        if (br != null) {
-//            br.close();
-//        }
-//        if (inputStreamReader != null) {
-//            inputStreamReader.close();
-//        }
-//        if (errorStream != null) {
-//            errorStream.close();
-//        }
-//
-//    }
-//
-//    /**
-//     * 从视频中提取音频信息
-//     * @param videoUrl
-//     * @return
-//     */
-//    public static String videoToAudio(String videoUrl,String accFile){
-//        String aacFile = "";
-//        try {
-//            aacFile = TMP_PATH + "/" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
-//                    + UUID.randomUUID().toString().replaceAll("-", "") + ".mp3";
-//            String command =   FFMPEG_PATH + " -i "+ videoUrl + " -vn -acodec copy "+ aacFile;
-//            System.out.println("video to audio command : " + command);
-//            Process process = Runtime.getRuntime().exec(command);
-//            process.waitFor();
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//        return "";
-//    }
-//
-//    /**
-//     * FFmpeg全路径
-//     */
-//    private static final String FFMPEG_PATH = "D:\\java\\ffmpeg\\bin\\ffmpeg.exe";
-//    /**
-//     * 音频保存路径
-//     */
-//    private static final String TMP_PATH = "D:\\data\\test";
-//}

+ 2 - 0
jeecg-boot-module-system/src/main/resources/application-dev.yml

@@ -152,6 +152,8 @@ mybatis-plus:
       log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
 #jeecg专用配置
 jeecg:
+  ffmpeg:
+    bin: D:\java\ffmpeg\bin\ffmpeg.exe
   path:
     #文件上传根目录 设置
     upload: D://upFiles

+ 2 - 0
jeecg-boot-module-system/src/main/resources/application-prod.yml

@@ -141,6 +141,8 @@ mybatis-plus:
       table-underline: true
 #jeecg专用配置
 jeecg:
+  ffmpeg:
+    bin: /mnt/ffmpeg/bin
   path:
     #文件上传根目录 设置
     upload: /mnt/upload

+ 24 - 0
jeecg-boot-module-system/src/test/java/org/jeecg/SampleTest.java

@@ -10,6 +10,7 @@ import cn.com.ctop.common.module.utils.HttpUtils;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouCreativeService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouHistoryReportTaskService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -263,6 +264,29 @@ public class SampleTest {
         performanceSaleService.loadSalsePerformance();
     }
 
+    @Test
+    public void loadBtPlanData() {
+        List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
+        executorService = Executors.newFixedThreadPool(10);
+        tokens.forEach(token -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        //1:获取当日广告计划数据
+                        advertiserDataService.getAdvertiserPlan(token, "", null, null);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    } finally {
+                    }
+                }
+            });
+        });
+    }
+
+    @Autowired
+    private IByteDanceAdvertiserDataService advertiserDataService;
+
     @Autowired
     private IPerformanceSaleService performanceSaleService;
 

+ 14 - 3
module-common/src/main/java/cn/com/ctop/common/module/utils/CtopAdConstant.java

@@ -34,10 +34,21 @@ public class CtopAdConstant {
      */
     public static final String SYSTEM_SALE_AM_CODE = "f5a68aa2acf86e842100f0fa4b050d28";
 
-
-    public static final BigDecimal BYTEDANCE_MEDIA_TASK_COST = new BigDecimal("200000000");
-    public static final BigDecimal KUAISHOU_MEDIA_TASK_COST = new BigDecimal("200000000");
+    /**
+     * 头条销售媒体季度任务
+     */
+    public static final BigDecimal BYTEDANCE_MEDIA_TASK_COST = new BigDecimal("150000000");
+    /**
+     * 快手销售媒体季度任务
+     */
+    public static final BigDecimal KUAISHOU_MEDIA_TASK_COST = new BigDecimal("147000000");
+    /**
+     * 头条销售季度个人任务
+     */
     public static final BigDecimal BYTEDANCE_PERSONAL_TASK_COST = new BigDecimal("2400000");
+    /**
+     * 快手销售季度个人任务
+     */
     public static final BigDecimal KUAISHOU_PERSONAL_TASK_COST = new BigDecimal("2400000");
 
     /**

+ 1 - 2
module-toutiao/src/main/java/cn/com/ctop/toutiao/service/impl/ByteDanceAdvertiserDataServiceImpl.java

@@ -123,13 +123,12 @@ public class ByteDanceAdvertiserDataServiceImpl implements IByteDanceAdvertiserD
         }
         for (int i = 0; i < data.size(); i++) {
             JSONObject dataObject = data.getJSONObject(i);
+            System.out.println(dataObject.toJSONString());
             ByteDanceAdvertisePlan advertisePlan = new ByteDanceAdvertisePlan(dataObject, String.valueOf(token.getAccountId()));
             BigDecimal deepCpabid = dataObject.getBigDecimal("deep_cpabid");
             if (null != deepCpabid) {
                 advertisePlan.setDeepCpabid(deepCpabid);
             }
-
-
             advertisePlanService.saveOrUpdate(advertisePlan);
         }
         getAd(token, pageNum + 1, ids, date, updateDate);