Ver código fonte

Merge remote-tracking branch 'origin/master'

yumeng 5 anos atrás
pai
commit
d5054da58a

+ 103 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/MaterialCutFrameController.java

@@ -1,7 +1,13 @@
 package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.entity.MaterialCutFrame;
+import cn.com.ctop.common.module.entity.MaterialCutFrameTask;
+import cn.com.ctop.common.module.entity.MaterialInfo;
+import cn.com.ctop.common.module.entity.MaterialParameter;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
+import cn.com.ctop.common.module.service.IMaterialCutFrameTaskService;
+import cn.com.ctop.common.module.service.IMaterialInfoService;
+import cn.com.ctop.common.module.utils.Check;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -17,6 +23,8 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
 import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 
 /**
@@ -33,6 +41,10 @@ import java.util.List;
 public class MaterialCutFrameController {
     @Autowired
     private IMaterialCutFrameService materialCutFrameService;
+    @Autowired
+    private IMaterialInfoService materialInfoService;
+    @Autowired
+    private IMaterialCutFrameTaskService materialCutFrameTaskServiceTask;
 
     /**
      * 分页列表查询
@@ -168,4 +180,95 @@ public class MaterialCutFrameController {
         }
         return result;
     }
+
+
+    @AutoLog(value = "腾讯云抽帧按照素材创建时间筛选素材进行抽帧操作")
+    @ApiOperation(value = "腾讯云抽帧", notes = "腾讯云抽帧")
+    @GetMapping(value = "/getCosCutFrameByTime")
+    public Result getCosCutFrameByTime(@RequestParam(name = "startDate", required = true) String startDate,
+                                 @RequestParam(name = "endDate", required = true) String endDate) {
+        Result result = new Result();
+        result.setSuccess(true);
+
+        try {
+            List<MaterialInfo> materialInfos = materialInfoService.getListByDate(startDate, endDate);
+            if (!Check.isNull(materialInfos)) {
+                for (MaterialInfo materialInfo : materialInfos) {
+                    if (!Check.isNull(materialInfo)) {
+                        String code = materialInfo.getCode();
+                        materialCutFrameService.getCosCutFrame(materialInfo.getUrl(), code);
+                    }
+                }
+            }
+        }catch (Exception e){
+            log.error(e.getMessage());
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+
+        return result;
+    }
+
+    @AutoLog(value = "腾讯云抽帧--根据md5抽帧")
+    @ApiOperation(value = "腾讯云抽帧", notes = "腾讯云抽帧")
+    @GetMapping(value = "/getCosCutFrame")
+    public Result getCosCutFrame(@RequestParam(name = "code", required = true) String code) {
+        Result result = new Result();
+        result.setSuccess(true);
+
+        try {
+            MaterialInfo materialInfo = materialInfoService.getMaterialInfoByCode(code);
+            if (!Check.isNull(materialInfo)) {
+                materialCutFrameService.getCosCutFrame(materialInfo.getUrl(), code);
+            }
+        }catch (Exception e){
+            log.error(e.getMessage());
+            e.printStackTrace();
+            result.setSuccess(false);
+        }
+
+        return result;
+    }
+
+
+    @AutoLog(value = "腾讯云抽帧--获取任务状态并将图片入库")
+    @ApiOperation(value = "腾讯云抽帧", notes = "腾讯云抽帧")
+    @GetMapping(value = "/loadCosCutFrame")
+    public Result loadCosCutFrame() {
+        Result result = new Result();
+        result.setSuccess(true);
+
+        log.info("开始抽帧定时任务");
+        QueryWrapper<MaterialCutFrameTask> taskQueryWrapper = new QueryWrapper<>();
+        taskQueryWrapper.eq("job_status", 0);
+        taskQueryWrapper.eq("cloud_type",2);  //2为腾讯云 1为阿里云
+        List<MaterialCutFrameTask> list = materialCutFrameTaskServiceTask.list(taskQueryWrapper);
+
+        if (Check.isNull(list)) {
+            result.setCode(500);
+            result.setSuccess(false);
+            return result;
+        }
+
+        ExecutorService executorService = Executors.newFixedThreadPool(5);
+        list.forEach(cutFrameTask -> {
+            executorService.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                    //获取广告计划信息数据
+                    materialCutFrameService.loadCosCutFrame(cutFrameTask.getJobId(), cutFrameTask.getVideoSignature());
+                    }catch (Exception e){
+                        log.error(e.getMessage());
+                        e.printStackTrace();
+                    }
+                }
+            });
+        });
+
+        return result;
+    }
+
+
+
 }

+ 2 - 0
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/job/CutFrameJob.java

@@ -35,6 +35,7 @@ public class CutFrameJob implements Job {
                 log.info("开始抽帧定时任务");
                 QueryWrapper<MaterialCutFrameTask> taskQueryWrapper = new QueryWrapper<>();
                 taskQueryWrapper.eq("job_status", 0);
+                //taskQueryWrapper.eq("cloud_type", 2);
                 List<MaterialCutFrameTask> list = taskService.list(taskQueryWrapper);
 
                 if (Check.isNull(list)) {
@@ -47,6 +48,7 @@ public class CutFrameJob implements Job {
                         public void run() {
                             //获取广告计划信息数据
                             materialCutFrameService.loadCutFrame(cutFrameTask.getJobId(), cutFrameTask.getVideoSignature());
+                            //materialCutFrameService.loadCosCutFrame(cutFrameTask.getJobId(), cutFrameTask.getVideoSignature());  //腾讯云任务状态查询以及图片下载
                         }
                     });
                 });

+ 7 - 1
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/service/impl/ProjectMemberServiceImpl.java

@@ -86,9 +86,15 @@ public class ProjectMemberServiceImpl extends ServiceImpl<ProjectMemberMapper, P
         } else if (roleCode.equals("admin")) {
             projectMemberList = memberMapper.adminProjects(mediaIds);
         } else if (roleCode.equals("operator") || roleCode.equals("operationAssistant") || roleCode.equals("touTiaoOperationManager")) {
-            projectMemberList = memberMapper.operationProjects(userId, mediaIds);
+            projectMemberList = memberMapper.designProjects(userId, mediaIds);
+        }else{
+            //如果以上角色都不是的话直接查询此角色所属项目
+            projectMemberList = memberMapper.designProjects(userId, mediaIds);
         }
 
+        if(null == projectMemberList){
+            projectMemberList = new ArrayList<>();
+        }
         return projectMemberList;
     }
 

+ 4 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/IMaterialCutFrameService.java

@@ -21,4 +21,8 @@ public interface IMaterialCutFrameService extends IService<MaterialCutFrame> {
 
     List<MaterialCutFrame> getListByVideoSignature(String signature);
 
+    void getCosCutFrame(String url, String materialId) throws IOException;  //腾讯云抽帧
+
+    void loadCosCutFrame(String jobId, String videoSignature);  //腾讯云抽帧任务状态查询以及数据入库
+
 }

+ 93 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialCutFrameServiceImpl.java

@@ -7,9 +7,11 @@ import cn.com.ctop.common.module.mapper.MaterialCutFrameMapper;
 import cn.com.ctop.common.module.service.IMaterialCutFrameService;
 import cn.com.ctop.common.module.service.IMaterialCutFrameTaskService;
 import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.common.module.utils.CosUtil;
 import cn.com.ctop.common.module.utils.LoadFileUtil;
 import cn.com.ctop.common.module.utils.MpsUtils;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.aliyuncs.DefaultAcsClient;
 import com.aliyuncs.IAcsClient;
@@ -20,7 +22,9 @@ import com.aliyuncs.mts.model.v20140618.SubmitSnapshotJobResponse;
 import com.aliyuncs.profile.DefaultProfile;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -224,5 +228,94 @@ public class MaterialCutFrameServiceImpl extends ServiceImpl<MaterialCutFrameMap
     }
 
 
+    //腾讯云抽帧
+    @Override
+    public void getCosCutFrame(String url, String materialId) throws IOException {
+        try {
+
+            QueryWrapper<MaterialCutFrameTask> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("video_signature", materialId);
+            queryWrapper.last("limit 1");
+            MaterialCutFrameTask checkCutFrame = cutFrameTaskService.getOne(queryWrapper);
+            if (!Check.isNull(checkCutFrame)) {
+                log.info("已存推荐封面");
+                return;
+            }
+
+            //抽帧ossOutputObject1
+            String ossOutputObject1 = "/cutFrame/" + materialId + "/_";
+            String replaceUrl = url.replace("https://" + CosUtil.bucket + ".cos.ap-chongqing.myqcloud.com", "");  //地址
+            String resp = CosUtil.processMedia(replaceUrl, ossOutputObject1);
+            JSONObject respJson = JSONObject.parseObject(resp);
+            String jobId = respJson.getString("TaskId"); //{"Response": {"TaskId": "2600000655-WorkflowTask-c0b385f27c4993437029b5da175542aet0","RequestId": "4c23ce23-087f-4d4b-b73b-907d77d6d78d" } }
+            MaterialCutFrameTask cutFrameTask = new MaterialCutFrameTask();
+            cutFrameTask.setJobStatus(0);
+            cutFrameTask.setJobId(jobId);
+            cutFrameTask.setVideoSignature(materialId);
+            cutFrameTaskService.save(cutFrameTask);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+    }
+
+
+    //抽帧任务状态查询,如果完成则把抽帧入库
+    @Override
+    public void loadCosCutFrame(String jobId, String videoSignature) {
+        try {
+            String resp = CosUtil.describeTaskDetail(jobId);
+            if(StringUtils.isBlank(resp)){
+                return;
+            }
+
+            JSONObject respJson = JSONObject.parseObject(resp);
+            String status = respJson.getString("Status");
+
+            if(!"FINISH".equals(status)){
+                return;
+            }
+
+            JSONArray resultSetArray = respJson.getJSONObject("WorkflowTask").getJSONArray("MediaProcessResultSet");
+            if (Check.isNull(resultSetArray)) {
+                return;
+            }
+            JSONObject resultSetObject = resultSetArray.getJSONObject(0);
+            if (Check.isNull(resultSetObject)) {
+                return;
+            }
+            JSONArray snapshotArray = resultSetObject.getJSONObject("SampleSnapshotTask").getJSONObject("Output").getJSONArray("ImagePathSet");
+
+            if (Check.isNull(snapshotArray)) {
+                return;
+            }
+
+            for (int i=0; i< snapshotArray.size(); i++){
+                String imagePath = snapshotArray.getString(i);
+                String urlStr = "https://" + CosUtil.bucket + ".cos.ap-chongqing.myqcloud.com" + imagePath;
+
+                //下载到本地获取图片md5
+                String cutFramePath = LoadFileUtil.downLoadFromUrl(urlStr, imageUpLoadPath);
+                String cutFrameMd5 = LoadFileUtil.getMD5(cutFramePath);
+
+                MaterialCutFrame cutFrame = new MaterialCutFrame();
+                cutFrame.setSignature(cutFrameMd5);
+                cutFrame.setUrl(urlStr);
+                cutFrame.setVideoSignature(videoSignature);
+                cutFrame.setImageIndex(i);
+                this.save(cutFrame);
+            }
+
+            QueryWrapper<MaterialCutFrameTask> updateQueryWrapper = new QueryWrapper<>();
+            updateQueryWrapper.eq("job_id", jobId);
+            updateQueryWrapper.eq("video_signature", videoSignature);
+            MaterialCutFrameTask updateTask = new MaterialCutFrameTask();
+            updateTask.setJobStatus(1);
+            cutFrameTaskService.update(updateTask, updateQueryWrapper);
+        } catch (Exception e) {
+            log.error(e.getMessage());
+        }
+
+    }
+
 
 }

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/service/impl/MaterialInfoServiceImpl.java

@@ -380,6 +380,7 @@ public class MaterialInfoServiceImpl extends ServiceImpl<MaterialInfoMapper, Mat
                                 try {
                                     log.info("开始抽帧");
                                     materialCutFrameService.getCutFrame(videoUrl, materialInfo.getCode(), secondDuration, height, width);
+                                    //materialCutFrameService.getCosCutFrame(videoUrl, materialInfo.getCode());  //腾讯云抽帧
                                 } catch (Exception e) {
                                     e.printStackTrace();
                                 }

+ 148 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/CosUtil.java

@@ -0,0 +1,148 @@
+package cn.com.ctop.common.module.utils;
+
+import com.tencentcloudapi.common.Credential;
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
+import com.tencentcloudapi.common.profile.ClientProfile;
+import com.tencentcloudapi.common.profile.HttpProfile;
+import com.tencentcloudapi.mps.v20190612.MpsClient;
+import com.tencentcloudapi.mps.v20190612.models.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shiro.codec.Base64;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.UnsupportedEncodingException;
+import java.util.HashMap;
+import java.util.Map;
+
+
+//@Slf4j
+public class CosUtil {
+    public static final String secretId = "AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets";
+    public static final String secretKey = "tXzuwMfplTTK3c9GFUyETilasvQfePu9";
+    public static final String region = "ap-chongqing";
+    public static final String bucket = "part-1301855440";
+    public static final String host = "https://media-1301855440.cos.ap-chongqing.myqcloud.com";
+
+
+    //创建采样视频截图模板
+    public static void createSampleSnapshotTemplate(){
+        try{
+
+            Credential cred = new Credential(secretId, secretKey);
+
+            HttpProfile httpProfile = new HttpProfile();
+            httpProfile.setEndpoint("mps.tencentcloudapi.com");
+
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setHttpProfile(httpProfile);
+
+            MpsClient client = new MpsClient(cred, region, clientProfile);
+
+            String params = "{\"Name\":\"sampleSnapshotTemplate1\",\"SampleType\":\"Percent\",\"SampleInterval\":7}";
+
+            CreateSampleSnapshotTemplateRequest req = CreateSampleSnapshotTemplateRequest.fromJsonString(params, CreateSampleSnapshotTemplateRequest.class);
+
+            CreateSampleSnapshotTemplateResponse resp = client.CreateSampleSnapshotTemplate(req);
+
+            System.out.println(CreateSampleSnapshotTemplateRequest.toJsonString(resp));
+        } catch (TencentCloudSDKException e) {
+            System.out.println(e.toString());
+        }
+    }
+
+    /**
+     * 视频处理模块
+     * 查询已经创建的模板
+     */
+    public static void DescribeSampleSnapshotTemplates(){
+            try{
+                Credential cred = new Credential(secretId, secretKey);
+
+                HttpProfile httpProfile = new HttpProfile();
+                httpProfile.setEndpoint("mps.tencentcloudapi.com");
+
+                ClientProfile clientProfile = new ClientProfile();
+                clientProfile.setHttpProfile(httpProfile);
+
+                MpsClient client = new MpsClient(cred, region, clientProfile);
+
+                String params = "{}";
+                DescribeSampleSnapshotTemplatesRequest req = DescribeSampleSnapshotTemplatesRequest.fromJsonString(params, DescribeSampleSnapshotTemplatesRequest.class);
+
+                DescribeSampleSnapshotTemplatesResponse resp = client.DescribeSampleSnapshotTemplates(req);
+
+                System.out.println(DescribeSampleSnapshotTemplatesRequest.toJsonString(resp));
+            } catch (TencentCloudSDKException e) {
+                System.out.println(e.toString());
+            }
+    }
+
+    //查询抽帧任务状态
+    public static String describeTaskDetail(String taskId){
+            try{
+                Credential cred = new Credential(secretId, secretKey);
+
+                HttpProfile httpProfile = new HttpProfile();
+                httpProfile.setEndpoint("mps.tencentcloudapi.com");
+
+                ClientProfile clientProfile = new ClientProfile();
+                clientProfile.setHttpProfile(httpProfile);
+
+                MpsClient client = new MpsClient(cred, region, clientProfile);
+
+                String params = "{\"TaskId\":\"" + taskId + "\"}";
+                DescribeTaskDetailRequest req = DescribeTaskDetailRequest.fromJsonString(params, DescribeTaskDetailRequest.class);
+
+                DescribeTaskDetailResponse resp = client.DescribeTaskDetail(req);
+
+                System.out.println(DescribeTaskDetailRequest.toJsonString(resp));
+                return DescribeTaskDetailRequest.toJsonString(resp);
+            } catch (TencentCloudSDKException e) {
+                System.out.println(e.toString());
+                return null;
+            }
+    }
+
+    //抽帧      42095--已经创建好的采样截图模板,每7%抽一张,一共15张,第一张首帧
+    //videoPath视频路径,包括文件名 高清.mp4     snapshotPath 视频截图路径(包括名字) /高清
+    public static String processMedia(String videoPath, String snapshotPath){
+        try{
+            Credential cred = new Credential(secretId, secretKey);
+
+            HttpProfile httpProfile = new HttpProfile();
+            httpProfile.setEndpoint("mps.tencentcloudapi.com");
+
+            ClientProfile clientProfile = new ClientProfile();
+            clientProfile.setHttpProfile(httpProfile);
+
+            MpsClient client = new MpsClient(cred, region, clientProfile);
+
+            String params = "{\"InputInfo\":{\"Type\":\"COS\",\"CosInputInfo\":{\"Bucket\":\"" + bucket + "\",\"Region\":\"" + region + "\",\"Object\":\"" + videoPath + "\"}},\"MediaProcessTask\":{\"SampleSnapshotTaskSet\":[{\"Definition\":42095,\"OutputStorage\":{\"Type\":\"COS\",\"CosOutputStorage\":{\"Bucket\":\"part-1301855440\",\"Region\":\"" + region + "\"}},\"OutputObjectPath\":\"" + snapshotPath + "\"}]}}";
+
+            ProcessMediaRequest req = ProcessMediaRequest.fromJsonString(params, ProcessMediaRequest.class);
+
+            ProcessMediaResponse resp = client.ProcessMedia(req);
+
+            System.out.println(ProcessMediaRequest.toJsonString(resp));
+            return ProcessMediaRequest.toJsonString(resp);
+        } catch (TencentCloudSDKException e) {
+            System.out.println(e.toString());
+            return null;
+        }
+    }
+
+
+    public static void main(String[] args) {
+        //创建采样截图模板
+        createSampleSnapshotTemplate();
+        //查询采样截图模板
+        //DescribeSampleSnapshotTemplates();
+        //查询抽帧任务状态
+        //describeTaskDetail();
+
+    }
+
+
+}

+ 1 - 0
module-ctop/src/main/java/cn/com/ctop/manage/modules/actor/entity/Prop.java

@@ -20,6 +20,7 @@ public class Prop {
     @TableId(type = IdType.AUTO)
     private Long id;
     private String name;
+    @TableField(value = "`desc`")
     private String desc;
     private String type;
     private String coverUrl;

+ 11 - 0
pom.xml

@@ -395,6 +395,17 @@
             <artifactId>javacv-platform</artifactId>
             <version>1.4.2</version>
         </dependency>
+        <!--<dependency>
+            <groupId>com.qcloud</groupId>
+            <artifactId>cos_api</artifactId>
+            <version>5.6.24</version>
+        </dependency>-->
+
+        <dependency>
+            <groupId>com.tencentcloudapi</groupId>
+            <artifactId>tencentcloud-sdk-java</artifactId>
+            <version>3.1.62</version><!-- 注:这里只是示例版本号,请获取并替换为 最新的版本号 -->
+        </dependency>
     </dependencies>
 
     <dependencyManagement>