fix:新增图片下载监测,对未下载图片重新放入队列

pull/75/head
DELL 1 year ago
parent ab6925a8cf
commit f3ee195183

@ -0,0 +1,74 @@
package cn.jyjz.xiaoyao.ocr.thread;
import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
import cn.jyjz.xiaoyao.ocr.dataobject.OcrPicture;
import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.List;
import java.util.concurrent.*;
@Slf4j
public class ImageDownloadMonitoring {
@Autowired
private OcrPictureService ocrPictureService;
private static Logger logger = LoggerFactory.getLogger(TaskQueue.class);
/**
*
*
* @return
*/
public boolean startImageDownloadMonitoring() {
Runnable runnable = new Runnable() {
@SneakyThrows
@Override
public void run() {
OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService");
logger.debug("图片下载监测中...");
while (true) {
try {
// 查询数据库中local_picture_url字段为null的图片数据
LambdaQueryWrapper<OcrPicture> ocrPictureLambdaQueryWrapper = new LambdaQueryWrapper<>();
ocrPictureLambdaQueryWrapper.isNull(OcrPicture::getLocalpictrueurl);
List<OcrPicture> ocrPictureList = ocrPictureService.list(ocrPictureLambdaQueryWrapper);
for (OcrPicture pictureOne : ocrPictureList) {
// 创建 PictureImgToLocalEntity 对象并赋值
PictureImgToLocalEntity entity = new PictureImgToLocalEntity();
entity.setPictureId(pictureOne.getId());
entity.setImgUrl(pictureOne.getImgurl());
String imgurl = pictureOne.getImgurl();
String localImagePath = "/server/data/images";
entity.setLocalPath(localImagePath + imgurl.substring(imgurl.lastIndexOf("/")));
//本地调试下载地址
// entity.setLocalPath("D:\\server\\data\\images" + imgurl.substring(imgurl.lastIndexOf("/")));
// 将对象添加到下载图片队列中
boolean isAddedToQueue = TaskQueue.pictureImgToLocalPushData(entity);
if(isAddedToQueue){
System.out.println("添加队列成功");
}
}
// 等待一段时间再继续检查
Thread.sleep(600000);
} catch (Exception e) {
logger.error("图片下载监测出错{}", e.getMessage());
Thread.sleep(5000);
}
}
}
};
Thread thread = new Thread(runnable);
thread.start();
return true;
}
}

@ -17,5 +17,7 @@ public class TaskRunner implements CommandLineRunner {
TaskThreadPool taskThreadPool = new TaskThreadPool(); TaskThreadPool taskThreadPool = new TaskThreadPool();
taskThreadPool.startPictureDisposePull(); taskThreadPool.startPictureDisposePull();
taskThreadPool.startPictureImgToLocalPull(); taskThreadPool.startPictureImgToLocalPull();
ImageDownloadMonitoring imageDownloadMonitoring = new ImageDownloadMonitoring();
imageDownloadMonitoring.startImageDownloadMonitoring();
} }
} }

Loading…
Cancel
Save