lvzhiqiang 1 年之前
父節點
當前提交
ce3bb723b7

+ 3 - 3
src/main/java/top/lvzhiqiang/config/MyPicJobs.java

@@ -25,7 +25,7 @@ public class MyPicJobs {
     /**
      * jsoup fuliba
      */
-    @Scheduled(cron = "0 0 18 * * ?", zone = SCHEDULED_ZONE)
+    @Scheduled(cron = "0 0 9 * * ?", zone = SCHEDULED_ZONE)
     public void jsoupFulibaPicJob() throws Exception {
         log.warn("jsoupFulibaPicJob开始==============================");
 
@@ -35,7 +35,7 @@ public class MyPicJobs {
     /**
      * jsoup fuliba
      */
-    @Scheduled(cron = "0 0 19 * * ?", zone = SCHEDULED_ZONE)
+    @Scheduled(cron = "0 0 10 * * ?", zone = SCHEDULED_ZONE)
     public void jsoupFulibaPicDetailJob1() throws Exception {
         log.warn("jsoupFulibaPicDetailJob1开始==============================");
 
@@ -45,7 +45,7 @@ public class MyPicJobs {
     /**
      * jsoup fuliba
      */
-    @Scheduled(cron = "0 0 20 * * ?", zone = SCHEDULED_ZONE)
+    @Scheduled(cron = "0 30 9 * * ?", zone = SCHEDULED_ZONE)
     public void jsoupFulibaPicDetailJob2() throws Exception {
         log.warn("jsoupFulibaPicDetailJob2开始==============================");
 

+ 9 - 0
src/main/java/top/lvzhiqiang/mapper/PictureInfoMapper.java

@@ -108,4 +108,13 @@ public interface PictureInfoMapper {
             " order by publish_time asc" +
             "</script>"})
     List<FileCrawlerImageLog> findJsoupFulibaPicDetailListByParams(Map<String, Object> params);
+
+    @Insert({"<script>" +
+            "INSERT ignore INTO file_crawler_image(old_name, new_name, category_id, log_id, size, path, remark, orgin_url, sort, modify_time) " +
+            " VALUES " +
+            "<foreach collection='list' item='p' index=\"index\" separator=\",\">" +
+            "   (#{p.oldName}, #{p.newName}, #{p.categoryId}, #{p.logId}, #{p.size}, #{p.path}, #{p.remark}, #{p.orginUrl}, #{p.sort}, now())" +
+            "</foreach>" +
+            "</script>"})
+    int insertIgnoreFileImageList(List<FileCrawlerImage> fileCrawlerImageList);
 }

+ 55 - 11
src/main/java/top/lvzhiqiang/service/impl/PictureInfoServiceImpl.java

@@ -5,7 +5,9 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import net.coobird.thumbnailator.Thumbnails;
+import net.coobird.thumbnailator.tasks.UnsupportedFormatException;
 import org.jsoup.Connection;
+import org.jsoup.HttpStatusException;
 import org.jsoup.Jsoup;
 import org.jsoup.nodes.Document;
 import org.jsoup.nodes.Element;
@@ -36,6 +38,7 @@ import java.io.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.Proxy;
+import java.net.SocketTimeoutException;
 import java.net.URLDecoder;
 import java.time.LocalDate;
 import java.util.ArrayList;
@@ -317,6 +320,7 @@ public class PictureInfoServiceImpl extends BaseServiceImpl<Object> implements P
                 crawlerImageLog.setPublishTime(publishTime);
                 int count = pictureInfoMapper.insertIgnoreFileCrawlerImageLog(crawlerImageLog);
                 findCount += count;
+                log.warn("jsoupFulibaPic item success:publishTime={},mainTitle={}", publishTime, mainTitle);
             }
 
             // 继续下一页
@@ -371,11 +375,18 @@ public class PictureInfoServiceImpl extends BaseServiceImpl<Object> implements P
                 Thread.sleep(5000L);
 
                 SpringUtils.getBean(PictureInfoServiceImpl.class).jsoupFulibaPicDetailSub(fileCrawlerImageLog.getMainUrl(), headerMap, fileCrawlerImageLog.getPublishTime(), fileCrawlerImageLog.getId());
+                if (2 == fileCrawlerImageLog.getStatus()) {
+                    fileCrawlerImageLog.setFailureCause("");
+                }
                 fileCrawlerImageLog.setStatus(1);
                 successCount++;
             } catch (Exception e) {
-                fileCrawlerImageLog.setFailureCause(e.getMessage());
-                fileCrawlerImageLog.setStatus(2);
+                fileCrawlerImageLog.setFailureCause(e.getMessage().length() > 200 ? e.getMessage().substring(0, 200) : e.getMessage());
+                if (e.getMessage().contains("timeoutCount equal imgEles size")) {
+                    fileCrawlerImageLog.setStatus(4);
+                } else {
+                    fileCrawlerImageLog.setStatus(2);
+                }
                 failCount++;
             } finally {
                 pictureInfoMapper.insertOrUpdateFileCrawlerImageLog(fileCrawlerImageLog);
@@ -398,21 +409,35 @@ public class PictureInfoServiceImpl extends BaseServiceImpl<Object> implements P
         String ftpThumbnailCrawlerBasePath = InitRunner.dicCodeMap.get("ftp_thumbnail_crawler_basepath").getCodeValue();
         List<String> delPathList = new ArrayList<>();
         String srcUrl = "";
+        List<FileCrawlerImage> fileCrawlerImageList = new ArrayList<>();
         try {
             fulibaDetailDocument = JsoupUtil.requestDocument(mainUrl, JsoupUtil.HTTP_GET, Proxy.NO_PROXY, null, headerMap, null);
-            log.warn("jsoupFulibaPicDetailSub start:mainUrl={},logId={}", mainUrl, logId);
+            log.warn("jsoupFulibaPicDetailSub start:mainUrl={},publishTime={},logId={}", mainUrl, publishTime, logId);
             Elements imgEles = fulibaDetailDocument.select("div.content > article.article-content").select("img");
             int i = 0;
             String parentPath = "1" + File.separator + publishTime.format(DateUtils.dateFormatter5);
+            Connection.Response response;
+            int timeoutCount = 0;
             for (Element imgEle : imgEles) {
                 srcUrl = imgEle.attr("src");
                 String altTitle = imgEle.attr("alt");
-
                 newName = FtpUtil.genImageName();
                 String prefx = srcUrl.substring(srcUrl.lastIndexOf("."));
                 newName = newName + prefx;
+                try {
+                    response = Jsoup.connect(srcUrl).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
+                } catch (SocketTimeoutException ioex) {
+                    timeoutCount++;
+                    continue;
+                } catch (HttpStatusException ioex) {
+                    try {
+                        response = Jsoup.connect(srcUrl).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
+                    } catch (Exception e) {
+                        timeoutCount++;
+                        continue;
+                    }
+                }
 
-                Connection.Response response = Jsoup.connect(srcUrl).method(Connection.Method.GET).ignoreContentType(true).timeout(50 * 1000).execute();
                 byte[] imageBytes = response.bodyAsBytes();
                 if (imageBytes.length == 0) {
                     // 过滤掉失效的图片链接
@@ -433,16 +458,21 @@ public class PictureInfoServiceImpl extends BaseServiceImpl<Object> implements P
                 fileCrawlerImage.setCategoryId(1L);
                 fileCrawlerImage.setOrginUrl(srcUrl);
                 fileCrawlerImage.setLogId(logId);
-                fileCrawlerImage.setSort(++i);
-                int count = pictureInfoMapper.insertIgnoreFileImage(fileCrawlerImage);
-                if (count > 0) {
+                if (true) {
+                    InputStream imageStream2 = new ByteArrayInputStream(imageBytes);
+                    ByteArrayOutputStream thumbnailOutputStream = new ByteArrayOutputStream();
+                    try {
+                        Thumbnails.of(imageStream2).size(300, 200).toOutputStream(thumbnailOutputStream);
+                    } catch (UnsupportedFormatException unsupportedFormatException) {
+                        imageStream2.close();
+                        thumbnailOutputStream.close();
+                        continue;
+                    }
+
                     InputStream imageStream1 = new ByteArrayInputStream(imageBytes);
                     FtpUtil.uploadFile(ftpImageCrawlerBasePath, parentPath, newName, imageStream1);
                     delPathList.add(ftpImageCrawlerBasePath + imageUrl);
 
-                    InputStream imageStream2 = new ByteArrayInputStream(imageBytes);
-                    ByteArrayOutputStream thumbnailOutputStream = new ByteArrayOutputStream();
-                    Thumbnails.of(imageStream2).size(300, 200).toOutputStream(thumbnailOutputStream);
                     ByteArrayInputStream thumbnailInputStream = new ByteArrayInputStream(thumbnailOutputStream.toByteArray());
                     FtpUtil.uploadFile(ftpThumbnailCrawlerBasePath, parentPath, newName, thumbnailInputStream);
                     delPathList.add(ftpThumbnailCrawlerBasePath + imageUrl);
@@ -450,7 +480,21 @@ public class PictureInfoServiceImpl extends BaseServiceImpl<Object> implements P
                     imageStream2.close();
                     thumbnailOutputStream.close();
                 }
+
+                fileCrawlerImage.setSort(++i);
+                fileCrawlerImageList.add(fileCrawlerImage);
+            }
+
+            if (!imgEles.isEmpty() && timeoutCount == imgEles.size()) {
+                log.warn("jsoupFulibaPicDetailSub timeoutCount is equals imgEles size,mainUrl={},publishTime={},timeoutCount={}", mainUrl, publishTime, timeoutCount);
+                throw new BusinessException(ResultCodeEnum.UNKNOWN_ERROR.getCode(), "timeoutCount equal imgEles size");
             }
+            if (!imgEles.isEmpty() && timeoutCount > 4) {
+                log.warn("jsoupFulibaPicDetailSub timeoutCount is Too many,mainUrl={},publishTime={},timeoutCount={}", mainUrl, publishTime, timeoutCount);
+                throw new BusinessException(ResultCodeEnum.UNKNOWN_ERROR.getCode(), "timeoutCount is Too many");
+            }
+
+            int count = pictureInfoMapper.insertIgnoreFileImageList(fileCrawlerImageList);
         } catch (Exception e) {
             // 异常,删除已经上传的文件
             if (!delPathList.isEmpty()) {

+ 29 - 0
src/main/resources/static/js/my-picture.js

@@ -3,6 +3,8 @@ $(function () {
     search(1, true, false);
 });
 
+var scale = 1;  // 初始缩放比例
+
 /**
  * 初始化其他操作
  */
@@ -57,6 +59,27 @@ function initOther() {
         $("#playvideo").css("display", "none");
         $("#bigpreview").css("display", "none");
     });
+
+    var minScale = 0.5;  // 最小缩放比例
+    var maxScale = 3;    // 最大缩放比例
+    var step = 0.05;     // 缩放步幅,改为较小值以平滑缩放
+    $('#modal-image').on('mousewheel', function (event) {
+        event.preventDefault();  // 防止页面滚动
+
+        if (event.originalEvent.deltaY < 0) {
+            // 鼠标滚轮向上滚动 -> 放大图片
+            scale += step;
+        } else {
+            // 鼠标滚轮向下滚动 -> 缩小图片
+            scale -= step;
+        }
+
+        // 限制缩放比例在 minScale 和 maxScale 之间
+        scale = Math.min(Math.max(scale, minScale), maxScale);
+
+        // 使用 CSS transform 属性缩放图片
+        $('#modal-image').css('transform', 'scale(' + scale + ')');
+    });
 }
 
 /**
@@ -87,6 +110,9 @@ function search(pageNo, startFlag, searchSelectFlag) {
         if (bigType == '爬虫') {
             genres = "福利吧";
             orderField = "fcil.publish_time";
+        } if (bigType == '上传') {
+            genres = "";
+            orderField = "fi.create_time";
         } else {
             orderField = "vi.issue_date";
         }
@@ -358,6 +384,9 @@ function initContentEvent() {
             $("#modal").css("display", "none");
             $("#modal").find("img").attr("src", "");
         }
+
+        scale = 1;
+        $('#modal-image').css('transform', 'scale(' + scale + ')');
     });
     $("#modal").dblclick(function () {
         $(this).hide();

+ 4 - 0
src/main/resources/static/picture.html

@@ -178,6 +178,10 @@
         .close:focus {
             color: #bbb;
         }
+
+        .modal-content, #modal-image {
+            transition: transform 0.2s ease; /* 缩放时增加平滑过渡 */
+        }
     </style>
     <script type="text/javascript">
         function show() {