吴志根 пре 4 година
родитељ
комит
5b5efb89c8

+ 3 - 1
src/dsb/com/cnd3b/restcontroller/customer/wechatapplet/SQL/查询课件详细.sql

@@ -3,7 +3,9 @@ SELECT t1.tarchives_scid,
        t1.createdate,
        t1.fnotes,
        t1.ftitle,
-       t1.fvisitors,
+       (SELECT count(DISTINCT tuserid)
+        FROM tuser_study
+        WHERE tarchives_scid = t1.tarchives_scid) fvisitors,
        t1.fisontop,
        t1.fiscandownload
 FROM tarchives_sc t1

+ 129 - 0
src/dsb/com/cnd3b/restcontroller/enterprise/datacenter/datacenter.java

@@ -7,6 +7,9 @@ import com.cnd3b.common.Controller;
 import com.cnd3b.common.data.Rows;
 import com.cnd3b.common.data.SQLFactory;
 import com.cnd3b.utility.aliyun.oss.AliyunOSSConfigConstant;
+import com.cnd3b.utility.aliyun.oss.AliyunOSSUtil;
+import p2.common.parse.A;
+import p2.common.parse.S;
 
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -359,5 +362,131 @@ public class datacenter extends Controller {
         dbConnect.runSqlUpdate(sql);
     }
 
+    /**
+     * 申请视频转码
+     *
+     * @return
+     */
+    public String applyTranscoding() {
+        //阿里云视频转码模板
+        String templateId = "S00000001-200030";
+        //大于这个码率进行视频转码,mov格式的直接转码
+        int tempBitrate = 1800;
+        //获取支持的视频格式列表
+        ArrayList<String> listVideo = getSupportVieoList();
+
+        String key = content.getString("key");
+        if (key.toLowerCase().contains("mov")) {
+            AliyunOSSUtil.transcoding(templateId, key, key);
+            return getSucReturnObject().setData("MOV转码成功").toString();
+        }
+        //查询是否是可支持转码的视频
+        boolean isVideo = false;
+        for (String str : listVideo) {
+            if (key.toLowerCase().contains(str.toLowerCase())) {
+                isVideo = true;
+                break;
+            }
+        }
+        if (isVideo) {
+            String res = AliyunOSSUtil.submitMediaInfoJob(key);
+            JSONObject jsonObject = JSONObject.parseObject(res);
+            //码率
+            String bitrate = "0";
+            if (jsonObject.containsKey("mediaInfoJob")) {
+                JSONObject mediaInfoJob_jsonObject = jsonObject.getJSONObject("mediaInfoJob");
+                if (mediaInfoJob_jsonObject.containsKey("properties")) {
+                    JSONObject properties_jsonObject = mediaInfoJob_jsonObject.getJSONObject("properties");
+                    bitrate = properties_jsonObject.getString("bitrate");
+                }
+            }
+            System.err.println(bitrate);
+            if (Double.parseDouble(bitrate) > tempBitrate) {
+                AliyunOSSUtil.transcoding(templateId, key, key);
+                return getSucReturnObject().setData("转码成功").toString();
+            } else {
+                return getSucReturnObject().setData("码率低于" + tempBitrate + ",无须转码").toString();
+            }
+        } else {
+            return getSucReturnObject().setData("非视频格式,无法转码").toString();
+        }
+
+    }
+
+    public String applyTranscodingOfPath() {
+        String folderPath = content.getString("folderPath");
+        List<String> list = getOssFileList(folderPath);
+        //阿里云视频转码模板
+        String templateId = "S00000001-200030";
+        //大于这个码率进行视频转码,mov格式的直接转码
+        int tempBitrate = 1800;
+
+        for (String keyPath : list) {
+
+            String key = keyPath;
+            if (key.toLowerCase().contains("mov")) {
+                AliyunOSSUtil.transcoding(templateId, key, key);
+                System.err.println("MOV转码成功:" + keyPath);
+            } else {
+                ArrayList<String> listVideo = getSupportVieoList();
+                //查询是否是可支持转码的视频
+                boolean isVideo = false;
+                for (String str : listVideo) {
+                    if (key.toLowerCase().contains(str.toLowerCase())) {
+                        isVideo = true;
+                        break;
+                    }
+                }
+                if (isVideo) {
+                    String res = AliyunOSSUtil.submitMediaInfoJob(key);
+                    JSONObject jsonObject = JSONObject.parseObject(res);
+                    //码率
+                    String bitrate = "0";
+                    if (jsonObject.containsKey("mediaInfoJob")) {
+                        JSONObject mediaInfoJob_jsonObject = jsonObject.getJSONObject("mediaInfoJob");
+                        if (mediaInfoJob_jsonObject.containsKey("properties")) {
+                            JSONObject properties_jsonObject = mediaInfoJob_jsonObject.getJSONObject("properties");
+                            bitrate = properties_jsonObject.getString("bitrate");
+                        }
+                    }
+                    System.err.println(bitrate);
+                    if (Double.parseDouble(bitrate) > tempBitrate) {
+                        AliyunOSSUtil.transcoding(templateId, key, key);
+                        System.err.println("转码成功:" + keyPath);
+
+                    } else {
+                        System.err.println("码率低于" + tempBitrate + ",无须转码");
+
+                    }
+                } else {
+                    System.err.println("非视频格式,无法转码");
+
+                }
+            }
+
+        }
+        return getSucReturnObject().toString();
+    }
+
+    //支持转转码的格式
+    public ArrayList<String> getSupportVieoList() {
+        //3GP、AVI、FLV、MP4、M3U8、MPG、ASF、WMV、MKV、MOV、TS、WebM、MXF
+        ArrayList<String> list = new ArrayList<>();
+        list.add("3GP");
+        list.add("AVI");
+        list.add("FLV");
+        list.add("MP4");
+        list.add("M3U8");
+        list.add("MPG");
+        list.add("ASF");
+        list.add("WMV");
+        list.add("MKV");
+        list.add("MOV");
+        list.add("TS");
+        list.add("WebM");
+        list.add("MXF");
+        return list;
+    }
+
 
 }

+ 255 - 0
src/dsb/com/cnd3b/service/OssService.java

@@ -0,0 +1,255 @@
+//package com.cnd3b.service;
+//
+//import com.alibaba.fastjson.JSONArray;
+//import com.alibaba.fastjson.JSONObject;
+//import com.aliyuncs.DefaultAcsClient;
+//import com.aliyuncs.IAcsClient;
+//import com.aliyuncs.exceptions.ClientException;
+//import com.aliyuncs.exceptions.ServerException;
+//import com.aliyuncs.mts.model.v20140618.*;
+//import com.aliyuncs.profile.DefaultProfile;
+//import com.cnd3b.common.BaseClass;
+//import com.cnd3b.utility.WebRequest;
+//import org.apache.commons.lang.exception.ExceptionUtils;
+//import p2.common.parse.J;
+//
+//import java.io.UnsupportedEncodingException;
+//import java.net.URLEncoder;
+//
+//public class OssService extends BaseClass implements Runnable {
+//    @Override
+//    public void run() {
+//        System.err.println("OssService");
+//
+//    }
+//
+//    private static String accessKeyId = "LTAI5tASc17g95ABAqwUAqNS";
+//    private static String accessKeySecret = "UUs8gERP91X8HGeWgeOa6jsAIGQhhK";
+//    private static String mpsRegionId = "cn-beijing";
+//    private static String pipelineId = "189f4d23997941089318d5117efc1857";
+//    private static String templateId = "S00000001-200040";
+//    private static String ossLocation = "oss-cn-beijing";
+//    private static String ossBucket = "jiusheng11";
+//    private static String ossInputObject = "change/实木地暖地板技术视频.mov";
+//    private static String ossOutputObject = "change/实木地暖地板技术视频_1.mov";
+//
+//    public static void main(String[] args) throws UnsupportedEncodingException, ClientException {
+//
+////        transcoding();
+////        queryMediaListByURL();
+//
+////        AddMedia("http://jiusheng11.oss-cn-beijing.aliyuncs.com/11/实木地暖地板技术视频.mp4");
+//        //transcoding("11/实木地暖地板技术视频.mp4", "11/实木地暖地板技术视频_2.mov");
+//        submitMediaInfoJob("tt/英文版1分钟.mp4");
+////        submitAnalysisJob("tt/123.mp4");
+//    }
+//
+//    public static void transcoding(String ossInputObject, String ossOutputObject) {
+//        // 创建DefaultAcsClient实例并初始化
+//        DefaultProfile profile = DefaultProfile.getProfile(
+//                mpsRegionId,      // 地域ID
+//                accessKeyId,      // RAM账号的AccessKey ID
+//                accessKeySecret); // RAM账号Access Key Secret
+//        IAcsClient client = new DefaultAcsClient(profile);
+//        // 创建API请求并设置参数
+//        SubmitJobsRequest request = new SubmitJobsRequest();
+//        // Input
+//        JSONObject input = new JSONObject();
+//        input.put("Location", ossLocation);
+//        input.put("Bucket", ossBucket);
+//        try {
+//            input.put("Object", URLEncoder.encode(ossInputObject, "utf-8"));
+//        } catch (UnsupportedEncodingException e) {
+//            throw new RuntimeException("input URL encode failed");
+//        }
+//        request.setInput(input.toJSONString());
+//        // Output
+//        String outputOSSObject;
+//        try {
+//            outputOSSObject = URLEncoder.encode(ossOutputObject, "utf-8");
+//        } catch (UnsupportedEncodingException e) {
+//            throw new RuntimeException("output URL encode failed");
+//        }
+//        JSONObject output = new JSONObject();
+//        output.put("OutputObject", outputOSSObject);
+//        // Ouput->Container
+////        JSONObject container = new JSONObject();
+////        container.put("Format", "mp4");
+////        output.put("Container", container.toJSONString());
+//        // Ouput->Video
+////        JSONObject video = new JSONObject();
+////        video.put("Codec", "H.264");
+////        video.put("Bitrate", "1500");
+////        video.put("Width", "1280");
+////        video.put("Fps", "25");
+////        output.put("Video", video.toJSONString());
+//        // Ouput->Audio
+////        JSONObject audio = new JSONObject();
+////        audio.put("Codec", "AAC");
+////        audio.put("Bitrate", "128");
+////        audio.put("Channels", "2");
+////        audio.put("Samplerate", "44100");
+////        output.put("Audio", audio.toJSONString());
+//        // Ouput->TemplateId
+//        output.put("TemplateId", "S00000001-200010");
+//        JSONArray outputs = new JSONArray();
+//        outputs.add(output);
+//        request.setOutputs(outputs.toJSONString());
+//        request.setOutputBucket(ossBucket);
+//        request.setOutputLocation(ossLocation);
+//        // PipelineId
+//        request.setPipelineId(pipelineId);
+//        // 发起请求并处理应答或异常
+//        SubmitJobsResponse response;
+//
+//        try {
+//            response = client.getAcsResponse(request);
+//            System.out.println("RequestId is:" + response.getRequestId());
+//            if (response.getJobResultList().get(0).getSuccess()) {
+//                System.out.println("JobId is:" + response.getJobResultList().get(0).getJob().getJobId());
+//            } else {
+//                System.out.println("SubmitJobs Failed code:" + response.getJobResultList().get(0).getCode() +
+//                        " message:" + response.getJobResultList().get(0).getMessage());
+//            }
+//        } catch (ServerException e) {
+//            e.printStackTrace();
+//        } catch (ClientException e) {
+//            e.printStackTrace();
+//        }
+//
+//
+//    }
+//
+//
+//    //根据视频源OSS地址查询媒体信息, 如: 媒体ID, 媒体状态及其他属性
+//    private static void queryMediaListByURL() throws ClientException, UnsupportedEncodingException {
+//        String ossHost = "http://jiusheng11.oss-cn-beijing.aliyuncs.com/";
+//        String ossObject = "22/实木地暖地板技术视频.mp4";
+//        //ossObject需要符合rfc3986标准
+//        String rfc3986Object = encodeByRFC3986(ossObject);
+//        // 创建DefaultAcsClient实例并初始化
+//        DefaultProfile profile = DefaultProfile.getProfile(
+//                mpsRegionId,      // 地域ID
+//                accessKeyId,      // RAM账号的AccessKey ID
+//                accessKeySecret); // RAM账号Access Key Secret
+//        DefaultAcsClient client = new DefaultAcsClient(profile);
+//        //查询媒体
+//        QueryMediaListByURLRequest request2 = new QueryMediaListByURLRequest();
+//        request2.setFileURLs(ossHost + rfc3986Object);
+//        QueryMediaListByURLResponse response = client.getAcsResponse(request2);
+//        System.out.println(JSONObject.toJSONString(response.getMediaList()));
+//    }
+//
+//    private static String encodeByRFC3986(String object) throws UnsupportedEncodingException {
+//        StringBuilder builder = new StringBuilder();
+//        String[] segments = object.split("/");
+//        for (int i = 0; i < segments.length; i++) {
+//            builder.append(percentEncode(segments[i]));
+//            if (i != segments.length - 1) {
+//                builder.append("/");
+//            }
+//        }
+//        return builder.toString();
+//    }
+//
+//    private static String percentEncode(String value) throws UnsupportedEncodingException {
+//        if (value == null) {
+//            return null;
+//        }
+//        return URLEncoder.encode(value, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
+//    }
+//
+//
+//    private static final String REGION = "cn-beijing";
+//    private static final String mtsEndpoint = "mts." + mpsRegionId + ".aliyuncs.com";
+//    private static DefaultAcsClient aliyunClient;
+//
+//
+//    public static void AddMedia(String fileURL) {
+//        try {
+//            DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
+//        } catch (ClientException e) {
+//            System.out.print(ExceptionUtils.getStackTrace(e));
+//            System.exit(1);
+//        }
+//        aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));
+//        AddMediaRequest request = new AddMediaRequest();
+//        request.setFileURL(fileURL);
+////        request.setMediaWorkflowId("829bed0300994057a49e4f16de95****");
+////        request.setMediaWorkflowId("064a10f717d84a92b537f51b2a8aae4a");
+//        try {
+//            AddMediaResponse response = aliyunClient.getAcsResponse(request);
+//            System.out.println(JSONObject.toJSONString(response));
+//        } catch (ServerException e) {
+//            System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
+//        } catch (ClientException e) {
+//            System.out.println("Code:" + e.getErrCode() + " Msg:" + e.getMessage());
+//        }
+//
+//    }
+//
+//    public static void submitMediaInfoJob(String Object) {
+//
+//        JSONObject jsonObject = new JSONObject();
+//        jsonObject.put("Bucket", ossBucket);
+//        jsonObject.put("Location", ossLocation);
+//        jsonObject.put("Object", Object);
+//        String json = jsonObject.toJSONString();
+//
+//
+//        try {
+//            DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
+//        } catch (ClientException e) {
+//            System.out.print(ExceptionUtils.getStackTrace(e));
+//            System.exit(1);
+//        }
+//        aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));
+//
+//        SubmitMediaInfoJobRequest request = new SubmitMediaInfoJobRequest();
+//        request.setInput(json);
+//        request.setPipelineId(pipelineId);
+//
+//        try {
+//            SubmitMediaInfoJobResponse response = aliyunClient.getAcsResponse(request);
+//            System.out.println(JSONObject.toJSONString(response));
+//        } catch (ClientException e) {
+//            e.printStackTrace();
+//        }
+//
+//
+//    }
+//
+//    public static void submitAnalysisJob(String Object) {
+//
+//        JSONObject jsonObject = new JSONObject();
+//        jsonObject.put("Bucket", ossBucket);
+//        jsonObject.put("Location", ossLocation);
+//        jsonObject.put("Object", Object);
+//        String json = jsonObject.toJSONString();
+//
+//
+//        try {
+//            DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
+//        } catch (ClientException e) {
+//            System.out.print(ExceptionUtils.getStackTrace(e));
+//            System.exit(1);
+//        }
+//        aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));
+//
+//        SubmitAnalysisJobRequest request = new SubmitAnalysisJobRequest();
+//        request.setInput(json);
+//        request.setPipelineId(pipelineId);
+//
+//        try {
+//            SubmitAnalysisJobResponse response = aliyunClient.getAcsResponse(request);
+//            System.out.println(JSONObject.toJSONString(response));
+//        } catch (ClientException e) {
+//            e.printStackTrace();
+//        }
+//
+//
+//    }
+//
+//
+//
+//}

+ 158 - 0
src/dsb/com/cnd3b/utility/aliyun/oss/AliyunOSSUtil.java

@@ -6,12 +6,23 @@ import com.aliyun.oss.HttpMethod;
 import com.aliyun.oss.OSS;
 import com.aliyun.oss.OSSClientBuilder;
 import com.aliyun.oss.model.*;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.exceptions.ServerException;
+import com.aliyuncs.mts.model.v20140618.SubmitJobsRequest;
+import com.aliyuncs.mts.model.v20140618.SubmitJobsResponse;
+import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobRequest;
+import com.aliyuncs.mts.model.v20140618.SubmitMediaInfoJobResponse;
+import com.aliyuncs.profile.DefaultProfile;
 import com.cnd3b.common.parameter.parameter;
+import org.apache.commons.lang.exception.ExceptionUtils;
 
 import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.sql.Date;
 import java.util.ArrayList;
 import java.util.Base64;
@@ -293,4 +304,151 @@ public class AliyunOSSUtil {
     }
 
 
+    private static String ossBucket = BUCKE_NAME_1;
+    private static String ossLocation = "oss-cn-hangzhou";
+    private static final String REGION = "cn-hangzhou";
+    private static String mpsRegionId = "cn-hangzhou";
+    private static final String mtsEndpoint = "mts." + mpsRegionId + ".aliyuncs.com";
+    private static DefaultAcsClient aliyunClient;
+    private static String pipelineId = "3852035b69474d508167f2af72d9dce4";
+    private static String accessKeyId = AccessKey_ID;
+    private static String accessKeySecret = AccessKey_Secret;
+
+
+    /**
+     * 调用本接口之后媒体处理服务会对输入文件进行媒体信息分析,返回输入文件的媒体信息。您可以通过查询媒体信息作业接口得到媒体信息分析结果。
+     *
+     * @param Object
+     * @return
+     */
+    public static String submitMediaInfoJob(String Object) {
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("Bucket", ossBucket);
+        jsonObject.put("Location", ossLocation);
+        jsonObject.put("Object", Object);
+        String json = jsonObject.toJSONString();
+
+
+        try {
+            DefaultProfile.addEndpoint(REGION, REGION, "Mts", mtsEndpoint);
+        } catch (ClientException e) {
+            System.out.print(ExceptionUtils.getStackTrace(e));
+            System.exit(1);
+        }
+        aliyunClient = new DefaultAcsClient(DefaultProfile.getProfile(REGION, accessKeyId, accessKeySecret));
+
+        SubmitMediaInfoJobRequest request = new SubmitMediaInfoJobRequest();
+        request.setInput(json);
+        request.setPipelineId(pipelineId);
+
+        try {
+            SubmitMediaInfoJobResponse response = aliyunClient.getAcsResponse(request);
+            return JSONObject.toJSONString(response);
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
+        return "";
+
+    }
+
+    public static void transcoding(String TemplateId, String ossInputObject, String ossOutputObject) {
+        // 创建DefaultAcsClient实例并初始化
+        DefaultProfile profile = DefaultProfile.getProfile(
+                mpsRegionId,      // 地域ID
+                accessKeyId,      // RAM账号的AccessKey ID
+                accessKeySecret); // RAM账号Access Key Secret
+        IAcsClient client = new DefaultAcsClient(profile);
+        // 创建API请求并设置参数
+        SubmitJobsRequest request = new SubmitJobsRequest();
+        // Input
+        JSONObject input = new JSONObject();
+        input.put("Location", ossLocation);
+        input.put("Bucket", ossBucket);
+        try {
+            input.put("Object", URLEncoder.encode(ossInputObject, "utf-8"));
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("input URL encode failed");
+        }
+        request.setInput(input.toJSONString());
+        // Output
+        String outputOSSObject;
+        try {
+            outputOSSObject = URLEncoder.encode(ossOutputObject, "utf-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new RuntimeException("output URL encode failed");
+        }
+        JSONObject output = new JSONObject();
+        output.put("OutputObject", outputOSSObject);
+        // Ouput->Container
+//        JSONObject container = new JSONObject();
+//        container.put("Format", "mp4");
+//        output.put("Container", container.toJSONString());
+        // Ouput->Video
+//        JSONObject video = new JSONObject();
+//        video.put("Codec", "H.264");
+//        video.put("Bitrate", "1500");
+//        video.put("Width", "1280");
+//        video.put("Fps", "25");
+//        output.put("Video", video.toJSONString());
+        // Ouput->Audio
+//        JSONObject audio = new JSONObject();
+//        audio.put("Codec", "AAC");
+//        audio.put("Bitrate", "128");
+//        audio.put("Channels", "2");
+//        audio.put("Samplerate", "44100");
+//        output.put("Audio", audio.toJSONString());
+        // Ouput->TemplateId
+        output.put("TemplateId", TemplateId);
+        JSONArray outputs = new JSONArray();
+        outputs.add(output);
+        request.setOutputs(outputs.toJSONString());
+        request.setOutputBucket(ossBucket);
+        request.setOutputLocation(ossLocation);
+        // PipelineId
+        request.setPipelineId(pipelineId);
+        // 发起请求并处理应答或异常
+        SubmitJobsResponse response;
+
+        try {
+            response = client.getAcsResponse(request);
+            System.out.println("RequestId is:" + response.getRequestId());
+            if (response.getJobResultList().get(0).getSuccess()) {
+                System.out.println("JobId is:" + response.getJobResultList().get(0).getJob().getJobId());
+            } else {
+                System.out.println("SubmitJobs Failed code:" + response.getJobResultList().get(0).getCode() +
+                        " message:" + response.getJobResultList().get(0).getMessage());
+            }
+        } catch (ServerException e) {
+            e.printStackTrace();
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+    public static List<String> getOssFileList(String folderPath) {
+        OSS client = new OSSClientBuilder().build(END_POINT, AccessKey_ID, AccessKey_Secret);
+        // 构造ListObjectsRequest请求。
+        ListObjectsRequest listObjectsRequest = new ListObjectsRequest(BUCKE_NAME_1);
+        // 设置prefix参数来获取fun目录下的所有文件。
+        listObjectsRequest.setPrefix(folderPath);
+        // 递归列举目录下的所有文件。
+        ObjectListing listing = client.listObjects(listObjectsRequest);
+        // 遍历所有文件。
+        List<String> keysList = new ArrayList<>();
+        for (OSSObjectSummary objectSummary : listing.getObjectSummaries()) {
+            if (!objectSummary.getKey().endsWith("/")) {
+                String key = objectSummary.getKey();
+//                System.err.println(key);
+                keysList.add(key);
+            }
+        }
+        client.shutdown();
+
+        return keysList;
+    }
+
+
 }