yumeng vor 4 Jahren
Ursprung
Commit
c74637ad48

+ 52 - 9
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -3,10 +3,8 @@ package org.jeecg.modules.ctop.controller;
 import cn.com.ctop.common.module.entity.*;
 import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
 import cn.com.ctop.common.module.service.*;
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.common.module.utils.CtopAdConstant;
-import cn.com.ctop.common.module.utils.ResultMapUtils;
-import cn.com.ctop.common.module.utils.StatusCode;
+import cn.com.ctop.common.module.utils.*;
+import cn.com.ctop.common.module.vo.ResFileDTO;
 import cn.com.ctop.kuaishou.modules.batch.service.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
 import cn.com.ctop.toutiao.modules.material.service.IByteDanceAdvertiserDataService;
@@ -26,6 +24,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -69,11 +68,54 @@ public class TestController {
     private IMaterialImageInfoService iMaterialImageInfoService;
     @Autowired
     private IBytedanceReportService bytedanceReportService;
-    static ExecutorService executorService = Executors.newFixedThreadPool(10);
+    static ExecutorService executorService = Executors.newFixedThreadPool(15);
     static ExecutorService videoService = Executors.newFixedThreadPool(5);
     static ExecutorService suzhaoService = Executors.newFixedThreadPool(5);
 
 
+
+    @GetMapping(value = "/getCut")
+    public void getCut() {
+        QueryWrapper<MaterialInfo> materialInfoQueryWrapper = new QueryWrapper<>();
+        materialInfoQueryWrapper.like("cover_url", "ctop-media.oss-cn-beijing.aliyuncs.com");
+        List<MaterialInfo> list = materialInfoService.list(materialInfoQueryWrapper);
+        if (!Check.isNull(list)) {
+            for (MaterialInfo materialInfo : list) {
+                executorService.submit(new Runnable() {
+                    @Override
+                    public void run() {
+                        try {
+                            String url = materialInfo.getCoverUrl();
+                            if (!Check.isNull(url)) {
+                                InputStream imageStream = LoadFileUtil.getFileStream(url);
+                                if (!Check.isNull(imageStream)) {
+                                    ResFileDTO jpg = CosUtils.uploadDetailInputStreamV2(imageStream, materialInfo.getCode() + ".jpg", "jpg", 0L, "zeroImage/");
+                                    String fileUrl = jpg.getFileUrl();
+                                    materialInfo.setCoverUrl(fileUrl);
+                                    boolean b = materialInfoService.saveOrUpdate(materialInfo);
+                                    if (b) {
+                                        log.info("修改成功,videoCode:{}", materialInfo.getCode());
+                                    }
+                                }
+                            }
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                });
+            }
+        }
+        // InputStream in, String fileName, String fileType, long fileSize, String fileSavePath
+
+
+    }
+
+
+
+
+
+
+
     @GetMapping(value = "/t")
     public String test() {
         Result<String> result = new Result<>();
@@ -94,7 +136,6 @@ public class TestController {
     }
 
 
-
     @GetMapping(value = "/getSuZhao")
     public void getSuZhao() throws JobExecutionException {
         try {
@@ -765,13 +806,15 @@ public class TestController {
             bytedanceReportService.bytedanceAsyncTaskCreate(startDate, endDate, token, 4);
         }
     }
+
     @Autowired
     private IBytedanceEffectVideoInfoService effectVideoInfoService;
+
     @GetMapping("/bytedance/effectVideo/get")
-    public Map<String,Object>effectVideoGet(String date){
-        Map<String,Object>result = new HashMap<>();
+    public Map<String, Object> effectVideoGet(String date) {
+        Map<String, Object> result = new HashMap<>();
         effectVideoInfoService.loadEffectVideo(date);
-        ResultMapUtils.setResultMap(result,StatusCode.COMMON_SUCCESS);
+        ResultMapUtils.setResultMap(result, StatusCode.COMMON_SUCCESS);
         return result;
     }
 }

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

@@ -58,7 +58,7 @@ spring:
   autoconfigure:
     exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
   datasource:
-    url: jdbc:mysql://172.30.0.4:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+    url: jdbc:mysql://139.186.27.96:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
     username: hcst
     password: test@20190531
     driver-class-name: com.mysql.jdbc.Driver
@@ -97,7 +97,7 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          url: jdbc:mysql://172.30.0.4:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
+          url: jdbc:mysql://139.186.27.96:3306/jeecg-boot?characterEncoding=UTF-8&useUnicode=true&useSSL=false
           username: hcst
           password: test@20190531
           driver-class-name: com.mysql.jdbc.Driver

+ 61 - 35
module-common/src/main/java/cn/com/ctop/common/module/utils/CosUtils.java

@@ -22,16 +22,17 @@ import java.util.UUID;
 
 public class CosUtils {
     private static final String ACCESSKEY = "AKIDE6IpMi8fJQRCg1iuWzFajjRs43kbbets";
-    private static final String SECRETKEY ="tXzuwMfplTTK3c9GFUyETilasvQfePu9";
+    private static final String SECRETKEY = "tXzuwMfplTTK3c9GFUyETilasvQfePu9";
     private static final String APPID = "1301855440";
-    private static final String BUCKETNAME = "media-"+APPID;
+    private static final String BUCKETNAME = "media-" + APPID;
     private static final String REGIONID = "ap-chongqing";
-    private static final String URL_PREFIX = "https://"+BUCKETNAME+".cos.ap-chongqing.myqcloud.com/";
+    private static final String URL_PREFIX = "https://" + BUCKETNAME + ".cos.ap-chongqing.myqcloud.com/";
     /**
      * https://media-1301855440.cos.ap-chongqing.myqcloud.com/MyFile1/1234.mp4
      */
     /**
      * 初始化CosClient相关配置, appid、accessKey、secretKey、region
+     *
      * @return
      */
     public static COSClient getCosClient() {
@@ -50,12 +51,12 @@ public class CosUtils {
     /**
      * URL_PREFIX+fileSavePath+fileName
      * 上传文件
-     * @return
-     * //绝对路径和相对路径都OK
+     *
+     * @return //绝对路径和相对路径都OK
      */
-    public static String uploadFile(String filePath,String fileSavePath,String fileName) {
+    public static String uploadFile(String filePath, String fileSavePath, String fileName) {
         File localFile = new File(filePath);
-        PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKETNAME, fileSavePath+fileName, localFile);
+        PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKETNAME, fileSavePath + fileName, localFile);
         // 设置存储类型, 默认是标准(Standard), 低频(standard_ia),一般为标准的
         putObjectRequest.setStorageClass(StorageClass.Standard);
         COSClient cc = getCosClient();
@@ -67,7 +68,7 @@ public class CosUtils {
             e.printStackTrace();
         } catch (CosClientException e) {
             e.printStackTrace();
-        }finally {
+        } finally {
             // 关闭客户端
             cc.shutdown();
         }
@@ -76,6 +77,7 @@ public class CosUtils {
 
     /**
      * 下载文件
+     *
      * @param bucketName
      * @param key
      * @return
@@ -93,6 +95,7 @@ public class CosUtils {
 
     /**
      * 删除文件
+     *
      * @param bucketName
      * @param key
      */
@@ -110,6 +113,7 @@ public class CosUtils {
 
     /**
      * 创建桶
+     *
      * @param bucketName
      * @return
      * @throws CosClientException
@@ -125,15 +129,18 @@ public class CosUtils {
         } finally {
         }
         return bucket;
-    };
+    }
+
+    ;
 
     /**
      * 删除桶
+     *
      * @param bucketName
      * @throws CosClientException
      * @throws CosServiceException
      */
-    public void deleteBucket(String bucketName){
+    public void deleteBucket(String bucketName) {
         COSClient cc = getCosClient();
         try {
             cc.deleteBucket(bucketName);
@@ -141,20 +148,24 @@ public class CosUtils {
             e.printStackTrace();
         } finally {
         }
-    };
+    }
+
+    ;
 
     /**
      * 判断桶是否存在
+     *
      * @param bucketName
      * @return
      */
-    public static boolean doesBucketExist(String bucketName){
+    public static boolean doesBucketExist(String bucketName) {
         COSClient cc = getCosClient();
         return cc.doesBucketExist(bucketName);
     }
 
     /**
      * 查看桶文件
+     *
      * @param bucketName
      * @return
      * @throws CosClientException
@@ -197,31 +208,32 @@ public class CosUtils {
     }
 
     /**
-     *查询一个 Bucket 所在的 Region。
+     * 查询一个 Bucket 所在的 Region。
+     *
      * @param bucketName
      * @return
      */
-    public static String getBucketLocation(String bucketName){
+    public static String getBucketLocation(String bucketName) {
         COSClient cosClient = getCosClient();
         // bucket 的命名规则为{name}-{appid} ,此处填写的存储桶名称必须为此格式
         return cosClient.getBucketLocation(bucketName);
     }
 
-    public static ResFileDTO uploadMultipartFile(MultipartFile file,String fileSavePath){
+    public static ResFileDTO uploadMultipartFile(MultipartFile file, String fileSavePath) {
         String fileName = file.getOriginalFilename();
         InputStream inputStream;
         ResFileDTO o = new ResFileDTO();
-        String fileType ;
+        String fileType;
         long fileSize = file.getSize();
         try {
             inputStream = file.getInputStream();
             FileType type = FileTypeJudge.getType(inputStream);
 
-            if(type == null || "null".equals(type.toString()) ||
-                    "XLS_DOC".equals(type.toString())|| "XLSX_DOCX".equals(type.toString()) ||
-                    "WPSUSER".equals(type.toString())|| "WPS".equals(type.toString())){
+            if (type == null || "null".equals(type.toString()) ||
+                    "XLS_DOC".equals(type.toString()) || "XLSX_DOCX".equals(type.toString()) ||
+                    "WPSUSER".equals(type.toString()) || "WPS".equals(type.toString())) {
                 fileType = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
-            }else{
+            } else {
                 fileType = type.toString().toLowerCase();
             }
 
@@ -232,7 +244,7 @@ public class CosUtils {
         }
 
         try {
-            o = uploadDetailInputStream(file.getInputStream(),fileName,fileType,fileSize,fileSavePath);
+            o = uploadDetailInputStream(file.getInputStream(), fileName, fileType, fileSize, fileSavePath);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -240,12 +252,12 @@ public class CosUtils {
     }
 
 
-    public static ResFileDTO uploadDetailInputStream (InputStream in, String fileName , String fileType, long fileSize,String fileSavePath) {
-        String uuidFileName = UUID.randomUUID().toString()+fileName.substring(fileName.lastIndexOf("."));
-        String fileUrl = URL_PREFIX+fileSavePath+uuidFileName;
+    public static ResFileDTO uploadDetailInputStream(InputStream in, String fileName, String fileType, long fileSize, String fileSavePath) {
+        String uuidFileName = UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."));
+        String fileUrl = URL_PREFIX + fileSavePath + uuidFileName;
         String md5key = uploadFileByInputStream(in, fileSavePath, uuidFileName);
         ResFileDTO o = new ResFileDTO();
-        if(md5key != null){
+        if (md5key != null) {
             o.setFileType(fileType);
             o.setFileName(fileName);
             o.setCFileName(uuidFileName);
@@ -256,9 +268,27 @@ public class CosUtils {
         return o;
     }
 
-    public static String uploadFileByInputStream(InputStream fileStream, String fileSavePath, String fileName){
+
+    public static ResFileDTO uploadDetailInputStreamV2(InputStream in, String fileName, String fileType, long fileSize, String fileSavePath) {
+        //      String uuidFileName = UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf("."));
+        String fileUrl = URL_PREFIX + fileSavePath + fileName;
+        String md5key = uploadFileByInputStream(in, fileSavePath, fileName);
+        ResFileDTO o = new ResFileDTO();
+        if (md5key != null) {
+            o.setFileType(fileType);
+            o.setFileName(fileName);
+            o.setCFileName(fileName);
+            o.setFileUrl(fileUrl);
+            o.setFileSize(fileSize);
+            o.setMd5key(md5key);
+        }
+        return o;
+    }
+
+
+    public static String uploadFileByInputStream(InputStream fileStream, String fileSavePath, String fileName) {
         ObjectMetadata metadata = new ObjectMetadata();
-        PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKETNAME, fileSavePath+fileName, fileStream,metadata);
+        PutObjectRequest putObjectRequest = new PutObjectRequest(BUCKETNAME, fileSavePath + fileName, fileStream, metadata);
         // 设置存储类型, 默认是标准(Standard), 低频(standard_ia),一般为标准的
         putObjectRequest.setStorageClass(StorageClass.Standard);
         COSClient cc = getCosClient();
@@ -270,7 +300,7 @@ public class CosUtils {
             e.printStackTrace();
         } catch (CosClientException e) {
             e.printStackTrace();
-        }finally {
+        } finally {
             // 关闭客户端
             cc.shutdown();
         }
@@ -278,11 +308,7 @@ public class CosUtils {
     }
 
 
-    public static void main(String[] args) {
-        String filepath = "D:\\1234.mp4";
-        String fileSavePath = "script-lib/wps/";
-        String fileName = UUID.randomUUID().toString()+filepath.substring(filepath.lastIndexOf("."));
-        String filePath = uploadFile(filepath, fileSavePath, fileName);
-        System.out.println(filePath);
-    }
+
+
+
 }

+ 19 - 0
module-common/src/main/java/cn/com/ctop/common/module/utils/LoadFileUtil.java

@@ -168,4 +168,23 @@ public class LoadFileUtil {
         return null;
 
     }
+
+
+    public static InputStream getFileStream(String url) {
+        try {
+            HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
+            connection.setReadTimeout(60000);
+            connection.setConnectTimeout(60000);
+            connection.setRequestMethod("GET");
+            if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
+                InputStream inputStream = connection.getInputStream();
+                return inputStream;
+            }
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
 }

+ 1 - 0
module-ctop/src/main/java/cn/com/ctop/manage/modules/edu/service/impl/EduLessonServiceImpl.java

@@ -46,6 +46,7 @@ public class EduLessonServiceImpl extends ServiceImpl<EduLessonMapper, EduLesson
         String result = HttpUtils2.httpGetRequest(url,headMap, jsonObject);
         ObjectMapper mapper = new ObjectMapper();
         try {
+
             JsonNode rootNode = mapper.readTree(result);
             int code = rootNode.get("code").asInt();
             if(code != 0){