fix: 解决图片下载检测程序问题

pull/76/head
shuliYao 1 year ago
parent 5fc9a02fdb
commit 9f94517852

@ -13,6 +13,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;
@Slf4j
@ -28,38 +29,42 @@ public class ImageDownloadMonitoring {
*
* @return
*/
public boolean startImageDownloadMonitoring() {
public boolean startImageDownloadMonitoring(String localImagePath) {
Runnable runnable = new Runnable() {
@SneakyThrows
@Override
public void run() {
OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService");
logger.debug("图片下载监测中...");
while (true) {
logger.debug("图片下载监测中...");
try {
// 查询数据库中local_picture_url字段为null的图片数据
LambdaQueryWrapper<OcrPicture> ocrPictureLambdaQueryWrapper = new LambdaQueryWrapper<>();
ocrPictureLambdaQueryWrapper.isNull(OcrPicture::getLocalpictrueurl);
List<OcrPicture> ocrPictureList = ocrPictureService.list(ocrPictureLambdaQueryWrapper);
List<OcrPicture> ocrPictureList = new ArrayList<>();
ocrPictureList = ocrPictureService.list(ocrPictureLambdaQueryWrapper);
logger.debug("待执行下载图片数量:{}",ocrPictureList.size());
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("添加队列成功");
boolean isAddedToQueue = false;
while (!isAddedToQueue) {
isAddedToQueue =TaskQueue.pictureImgToLocalPushData(entity);
if (!isAddedToQueue) {
logger.info("图片下载监测-添加队列失败,等待五秒后继续进行添加,图片id:{}",entity.getPictureId());
Thread.sleep(5000);
}
}
}
// 等待一段时间再继续检查
Thread.sleep(600000);
Thread.sleep(60000);
} catch (Exception e) {
logger.error("图片下载监测出错{}", e.getMessage());
Thread.sleep(5000);

@ -1,5 +1,6 @@
package cn.jyjz.xiaoyao.ocr.thread;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@ -12,12 +13,16 @@ import org.springframework.stereotype.Component;
*/
@Component
public class TaskRunner implements CommandLineRunner {
@Value("${ocr.api.wly.localImagePath}")
private String localImagePath;
@Override
public void run(String... args) throws Exception {
TaskThreadPool taskThreadPool = new TaskThreadPool();
taskThreadPool.startPictureDisposePull();
taskThreadPool.startPictureImgToLocalPull();
ImageDownloadMonitoring imageDownloadMonitoring = new ImageDownloadMonitoring();
imageDownloadMonitoring.startImageDownloadMonitoring();
imageDownloadMonitoring.startImageDownloadMonitoring(localImagePath);
}
}

Loading…
Cancel
Save