|
|
|
@ -2,17 +2,23 @@ package cn.jyjz.xiaoyao.ocr.api.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import cn.jyjz.xiaoyao.common.base.util.SpringUtils;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.PrevailCloudApi;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceParameter;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.entity.PictureSourceResult;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.api.utils.*;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.dataobject.OcrPicture;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.service.OcrPictureService;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.thread.TaskQueue;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.httputil.HttpClient;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.httputil.HttpMethod;
|
|
|
|
|
import cn.jyjz.xiaoyao.ocr.util.httputil.HttpParamers;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
|
|
|
import liquibase.pro.packaged.S;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
|
import org.apache.commons.collections.SequencedHashMap;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
@ -166,4 +172,50 @@ public class PrevailCloudApiImpl implements PrevailCloudApi {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 启动任务 图片下载监测
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean startImageDownloadMonitoring(String localImagePath) {
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
|
@SneakyThrows
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService");
|
|
|
|
|
logger.debug("图片下载监测中...");
|
|
|
|
|
// 查询数据库中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 thread = new Thread(runnable);
|
|
|
|
|
thread.start();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|