Commit af24f2c4 authored by 李洪明's avatar 李洪明

修改长传数据

parent 8932b4c9
......@@ -10,6 +10,7 @@ import com.bme.access.upload.module.dao.DataUploadTimeMapper;
import com.bme.access.upload.module.dao.InAndOutDateUploadFailMapper;
import com.bme.access.upload.module.dao.InAndOutDateUrlMapper;
import com.bme.access.upload.module.dao.TransportDateMapper;
import com.bme.access.upload.module.utils.Base64Utils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
......@@ -109,6 +110,7 @@ public class InAndOutDateService {
// 出入口编号
String entryExitNumber = Objects.equals(inAndOutDateUrl.getGatePostCode(), "GC-2MEN") ? "B" : Objects.equals(inAndOutDateUrl.getGatePostCode(), "GC-3MEN") ? "C" : Objects.equals(inAndOutDateUrl.getGatePostCode(), "GC_1MEN") ? "A" : "";
inAndOutDate.setEntryexitnumber(entryExitNumber);
inAndOutDate.setPhotos(Base64Utils.imgToBase64(inAndOutDateUrl.getInOutImage()));
// 道闸编号
if (StringUtils.isNotEmpty(entryExitNumber)) {
String barrierNumber = Objects.equals(inAndOutDateUrl.getInOrOut(), 1) ? entryExitNumber.concat( "01") : Objects.equals(inAndOutDateUrl.getInOrOut(), 2) ? entryExitNumber.concat( "02") : "";
......
......@@ -2,6 +2,7 @@ package com.bme.access.upload.module.utils;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Encoder;
import java.io.*;
import java.net.HttpURLConnection;
......@@ -157,6 +158,39 @@ public class Base64Utils {
return null;
}
public static String imgToBase64(String imageUrl) {
String encoder = "data:image/jpg;";
try {
URL url = new URL(imageUrl);
// 打开链接
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 设置请求方式为"GET"
conn.setRequestMethod("GET");
// 超时响应时间为5秒
conn.setConnectTimeout(5 * 1000);
// 通过输入流获取图片数据
InputStream inStream = conn.getInputStream();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
// 创建一个Buffer字符串
byte[] buffer = new byte[1024];
// 每次读取的字符串长度,如果为-1,代表全部读取完毕
int len = 0;
// 使用一个输入流从buffer里把数据读取出来
while ((len = inStream.read(buffer)) != -1) {
// 用输出流往buffer里写入数据,中间参数代表从哪个位置开始读,len代表读取的长度
outStream.write(buffer, 0, len);
}
// 关闭输入流
inStream.close();
BASE64Encoder base64Encoder = new BASE64Encoder();
encoder = encoder + base64Encoder.encode(outStream.toByteArray());
return encoder;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
public static void main(String[] args) {
byte[] bytes = getByteImgByUrl("https://q1.itc.cn/q_70/images03/20240430/59fe8596e4cb4824a6f27315328a3559.jpeg");
System.out.println(bytes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment