tujidelv 3 年之前
父节点
当前提交
957264d768

+ 14 - 0
src/main/java/top/lvzhiqiang/mapper/DicCodeMapper.java

@@ -54,4 +54,18 @@ public interface DicCodeMapper {
             "</if>" +
             "</script>"})
     List<DicCode> findByCodeDesc(String codeDesc, String order);
+
+    /**
+     * 根据codeKey模糊查询
+     */
+    @Select({"<script>" +
+            "select *  from dic_code WHERE delete_flag = 1" +
+            "<if test=\"codeKey != null and codeKey != ''\">" +
+            "   and code_key like concat('%',#{codeKey},'%')" +
+            "</if>" +
+            "<if test=\"order != null and order != ''\">" +
+            "   order by modify_time ${order}" +
+            "</if>" +
+            "</script>"})
+    List<DicCode> findByCodeKey(String codeKey, String order);
 }

+ 1 - 1
src/main/java/top/lvzhiqiang/mapper/VideoInfoMapper.java

@@ -55,7 +55,7 @@ public interface VideoInfoMapper {
     /**
      * 查询所有识别码
      */
-    @Select("select distinct identification_code from video_info WHERE type = 1")
+    @Select("select distinct identification_code from video_info WHERE type = 1 and delete_flag = 1")
     List<String> findAllIcode();
 
     /**

+ 39 - 24
src/main/java/top/lvzhiqiang/service/impl/BgServiceImpl.java

@@ -74,6 +74,8 @@ public class BgServiceImpl implements BgService {
     @Value("${spring.profiles.active}")
     private String env;
 
+    private String ignoreFileTypeSuffix = "";
+
     /**
      * findDicCode
      *
@@ -495,6 +497,10 @@ public class BgServiceImpl implements BgService {
                 videoInfoCastMapper.deleteAll();
             }
 
+            ignoreFileTypeSuffix = dicCodeMapper.findByCodeKey("ignore_filetype_suffix", null).stream()
+                    .filter(x -> x.getEnv().contains(env)).findFirst().get().getCodeValue();
+
+
             List<String> allIcode = videoInfoMapper.findAllIcode();
             getAllFilePaths(picPath, javAllInfo, allIcode);
 
@@ -941,10 +947,7 @@ public class BgServiceImpl implements BgService {
         StringBuffer picTime = new StringBuffer("{cover:");
 
         // 图片URL bigImage
-        String href = container.select("a.bigImage").first().attr("abs:href");
-
-        long start = System.currentTimeMillis();
-        Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
+        String qibingCover = qibings.concat("/cover/");
 
         String fileName = issueDate.concat(" ").concat(h3);
         byte[] imgUrlBytes = fileName.getBytes(StandardCharsets.UTF_8);
@@ -955,32 +958,43 @@ public class BgServiceImpl implements BgService {
         }
         fileName = fileName.concat(".jpg");
 
-        String qibingCover = qibings.concat("/cover/");
-        saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
-        picTime.append(System.currentTimeMillis() - start).append(",");
+        if (!new File(qibingPath.concat(qibingCover), fileName).exists()) {
+            String href = container.select("a.bigImage").first().attr("abs:href");
+
+            long start = System.currentTimeMillis();
+            Connection.Response response = Jsoup.connect(href).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
+
+            saveFile2(response.bodyStream(), qibingPath.concat(qibingCover), fileName);
+            picTime.append(System.currentTimeMillis() - start).append(",");
+        }
 
         videoInfo.setImgUrl(qibingCover.concat(fileName));
 
         // 图片URL img_gf
-        Elements sampleBoxEles = container.select("div#sample-waterfall").select("a");
-        long start2 = System.currentTimeMillis();
-        if (sampleBoxEles.size() > 0) {
-            Connection.Response responseImg;
-            String qibingImgGF = qibings.concat("/img_gf/");
-            for (Element sampleBoxEle : sampleBoxEles) {
-                String sampleBoxHref = sampleBoxEle.attr("href");
-                if (!sampleBoxHref.contains("http")) {
-                    sampleBoxHref = sampleBoxEle.attr("abs:href");
-                }
+        String qibingImgGF = qibings.concat("/img_gf/");
+
+        File qibingImgGFFile = new File(qibingPath.concat(qibingImgGF));
+        if (!qibingImgGFFile.exists() || qibingImgGFFile.listFiles().length == 0) {
+            Elements sampleBoxEles = container.select("div#sample-waterfall").select("a");
+            long start2 = System.currentTimeMillis();
+            if (sampleBoxEles.size() > 0) {
+                Connection.Response responseImg;
+
+                for (Element sampleBoxEle : sampleBoxEles) {
+                    String sampleBoxHref = sampleBoxEle.attr("href");
+                    if (!sampleBoxHref.contains("http")) {
+                        sampleBoxHref = sampleBoxEle.attr("abs:href");
+                    }
 
-                responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
-                String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
-                saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
+                    responseImg = Jsoup.connect(sampleBoxHref).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
+                    String sampleBoxFileName = sampleBoxHref.substring(sampleBoxHref.lastIndexOf("/") + 1);
+                    saveFile2(responseImg.bodyStream(), qibingPath.concat(qibingImgGF), sampleBoxFileName);
+                }
+            } else {
+                log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
             }
-        } else {
-            log.error("jsoupVideoInfo img_gf null,identificationCode={}", identificationCode);
+            picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
         }
-        picTime.append("img_gf:").append(System.currentTimeMillis() - start2).append("}");
 
         return picTime.toString();
     }
@@ -1059,7 +1073,8 @@ public class BgServiceImpl implements BgService {
                 getAllFilePaths(file.getAbsolutePath(), javAllInfo, allIcode);
             } else {
                 String fileName = file.getName();
-                if (!fileName.endsWith(".jpg") && !fileName.endsWith(".txt")) {
+                String fileSuffix = fileName.substring(fileName.lastIndexOf(".") + 1);
+                if (!ignoreFileTypeSuffix.contains(fileSuffix)) {
                     String parentName = file.getParentFile().getName();
                     // 识别码
                     String name = fileName.substring(10, fileName.lastIndexOf(".")).trim();