package com.dcsoft.file.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dcsoft.common.core.exception.ServiceException;
import com.dcsoft.file.utils.HttpUtil;
import com.dcsoft.file.utils.MinioUtil;
import com.dcsoft.file.utils.PictureUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class zctest {

    private static final ExecutorService executorService =  Executors.newFixedThreadPool(2);


    public static void main(String[] args) {
//        for (int i = 0; i < 6; i++) {
//            executorService.execute(connectTcpTask);
//        }
    }


    static Runnable connectTcpTask = new Runnable() {
        @Override
        public void run() {
            String filePath = "C:\\Users\\jingy\\Pictures\\test4.jpg";
            File file = new File(filePath);
            MultipartFile multipartFile = PictureUtils.getMultipartFile(file);
            String imgBase64 = null;
            try {
                imgBase64 = MinioUtil.getBase64String(multipartFile);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            checkPhoto(imgBase64);
        }};

    private static void checkPhoto(String imgBase64) {
        if (StringUtils.isNotEmpty(imgBase64)) {
            Map<String, Object> map = new HashMap<>();
            map.put("imgBase64", imgBase64);
            String body = HttpUtil.postData("http://81.68.71.142:7701/check/judgeImage", map);
            JSONObject object = JSONObject.parseObject(body);
            System.out.println("结果：" + object.toJSONString());
        }
    }
}
