From 9906987f77abf2f0669a44a877ad86ac730fdfdd Mon Sep 17 00:00:00 2001 From: 张磊磊 <201175954@qq.com> Date: 星期二, 12 十二月 2023 12:08:01 +0800 Subject: [PATCH] 图片转换 --- hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/helmet/service/impl/HelmetServiceImpl.java | 37 +++++++++++++++++++++++++++++++------ 1 files changed, 31 insertions(+), 6 deletions(-) diff --git a/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/helmet/service/impl/HelmetServiceImpl.java b/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/helmet/service/impl/HelmetServiceImpl.java index 1aff6fc..fb1a6d3 100644 --- a/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/helmet/service/impl/HelmetServiceImpl.java +++ b/hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/helmet/service/impl/HelmetServiceImpl.java @@ -1,6 +1,7 @@ package com.thhy.materials.modules.biz.helmet.service.impl; import com.alibaba.fastjson.JSONObject; +import org.apache.commons.io.FilenameUtils; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.thhy.general.common.BasicResult; @@ -9,20 +10,28 @@ import com.thhy.materials.modules.biz.helmet.entity.dto.TypeName; import com.thhy.materials.modules.biz.helmet.mapper.HelmetMapper; import com.thhy.materials.modules.biz.helmet.service.HelmetService; +import org.csource.common.MyException; +import org.csource.common.NameValuePair; +import org.csource.fastdfs.StorageClient; import org.springframework.stereotype.Service; import sun.misc.Cache; import javax.annotation.Resource; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.*; @Service public class HelmetServiceImpl implements HelmetService { @Resource private HelmetMapper helmetMapper; - + @Resource + private StorageClient storageClient; @Override public List<THelmetDevice> helmetServiceList() { @@ -163,7 +172,7 @@ } @Override - public BasicResult dataBox(JSONObject result) { + public BasicResult dataBox(JSONObject result) throws IOException, MyException { Integer type = Integer.valueOf(result.get("type").toString()); @@ -179,9 +188,25 @@ tDataAi.setEnterName(result.get("enterName").toString()); tDataAi.setEnterCode(result.get("enterCode").toString()); //图片上传 - + //ByteArrayInputStream bais = null; + byte[] bytes = Base64.getDecoder().decode(result.get("signAvatar").toString()); + //构建字节数组输入流 + //bais = new ByteArrayInputStream(bytes); +// BufferedImage bufferedImage = ImageIO.read(bais); +// //通过ImageIO把字节数组输入流转为BufferedImage +// //构建文件 +// File imageFile = new File(imageFileName); + NameValuePair[] nv = new NameValuePair[2]; + nv[0] = new NameValuePair("name","ai报警图片"); + nv[1] = new NameValuePair("uploadTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + String[] paths = storageClient.upload_file(bytes, "jpg",nv); + String p1 = paths[0]; + String p2 = paths[1]; + String path = p1+"/"+p2; //上边缺少图片处理 tDataAi.setSignTime(result.get("signTime").toString()); + tDataAi.setSignAvatar(path); + tDataAi.setSignBigAvatar(result.get("signBigAvatar").toString()); tDataAi.setChannelNo(result.get("channelNo").toString()); tDataAi.setX(result.getIntValue("x")); tDataAi.setY(result.getIntValue("y")); -- Gitblit v1.9.3