package org.jeecg.module.custom.ocr.api.thread.tasks;

import com.google.common.collect.Lists;
import org.jeecg.module.custom.ocr.api.entity.FormRecord;
import org.jeecg.module.custom.ocr.api.entity.LivePhoto;
import org.jeecg.module.custom.ocr.dataobject.OcrPicture;
import org.jeecg.module.custom.ocr.service.OcrPictureService;
import org.jeecg.module.custom.ocr.utils.SpringUtils;
import org.jeecg.module.custom.ocr.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * 无量云接口 数据处理队列
 *
 * @author hugh(shuli.yao) 1397940314@qq.com
 * @version 1.0
 * @date 2024/3/14 11:15
 */
public class PictureDisposeTask implements Runnable {
    protected Logger logger = LoggerFactory.getLogger(getClass());

    private FormRecord pictureSourceResult;

    public PictureDisposeTask(FormRecord pictureSourceResult) {
        this.pictureSourceResult = pictureSourceResult;
    }

    @Override
    public void run() {
        //1.对图片对象进行入库操作
        OcrPictureService ocrPictureService = SpringUtils.getBean("ocrPictureService");

        //获取当前任务中有多少图片
        List<LivePhoto> livePhotos = Lists.newArrayList();

        //定义新增集合对象
        List<OcrPicture> ocrPictureList = new ArrayList<>();

        for (LivePhoto livePhoto : livePhotos) {
            //检查图片地址是否为空
            if (StringUtils.isEmpty(livePhoto.getFileUrl())) {
                OcrPicture picture = new OcrPicture();
                // TODO: 字段对应转换
                picture.setImageUrl(livePhoto.getFileUrl());
                picture.setHistory(true);
                ocrPictureList.add(picture);
            }
        }

        //调用图片入库方法
        int size = ocrPictureService.savePictures(ocrPictureList);
    }
}
