Compare commits
34 Commits
master
...
fix/localP
@ -0,0 +1,79 @@
|
||||
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.ArrayList;
|
||||
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(String localImagePath) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@SneakyThrows
|
||||
@Override
|
||||
public void run() {
|
||||
OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService");
|
||||
// while (true) {
|
||||
logger.debug("图片下载监测中...");
|
||||
// try {
|
||||
// 查询数据库中local_picture_url字段为null的图片数据
|
||||
LambdaQueryWrapper<OcrPicture> ocrPictureLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
ocrPictureLambdaQueryWrapper.isNull(OcrPicture::getLocalpictrueurl);
|
||||
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();
|
||||
entity.setLocalPath(localImagePath + imgurl.substring(imgurl.lastIndexOf("/")));
|
||||
//本地调试下载地址
|
||||
// entity.setLocalPath("D:\\server\\data\\images" + imgurl.substring(imgurl.lastIndexOf("/")));
|
||||
// 将对象添加到下载图片队列中
|
||||
boolean isAddedToQueue = false;
|
||||
while (!isAddedToQueue) {
|
||||
isAddedToQueue =TaskQueue.pictureImgToLocalPushData(entity);
|
||||
if (!isAddedToQueue) {
|
||||
logger.info("图片下载监测-添加队列失败,等待五秒后继续进行添加,图片id:{}",entity.getPictureId());
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
// // 等待一段时间再继续检查
|
||||
// Thread.sleep(60000);
|
||||
// } catch (Exception e) {
|
||||
// logger.error("图片下载监测出错{}", e.getMessage());
|
||||
// Thread.sleep(5000);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
};
|
||||
Thread thread = new Thread(runnable);
|
||||
thread.start();
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,3 +1,3 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: dev
|
||||
active: pro
|
||||
|
Loading…
Reference in new issue