package com.zhgd.xmgl.modules.basicdata.api.image_ai.utils;

import cn.hutool.core.io.FileUtil;
import com.zhgd.xmgl.modules.basicdata.api.image_ai.Opencv;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;

import java.io.File;

@Slf4j
@UtilityClass
public class AiBroker {

	@FunctionalInterface
	public interface ApplyAs<T> {

		/**
		 * 执行业务逻辑,返回一个值
		 * @param imagePath
		 * @return
		 * @throws Exception
		 */
		String apply(String imagePath) throws Exception;

	}

	public String runAs(String rtsp, ApplyAs<T> func) {
		try {
			// 截图
			String imagePath = Opencv.createImage(rtsp);
			String result = func.apply(imagePath);
			// 删图
			FileUtil.del(new File(imagePath));
			return result;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
