|
@@ -1,15 +1,26 @@
|
|
|
package cn.iocoder.yudao.module.museum.service.museummodel;
|
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.module.museum.controller.admin.museummodel.vo.MuseummodelPageReqVO;
|
|
|
import cn.iocoder.yudao.module.museum.controller.admin.museummodel.vo.MuseummodelSaveVO;
|
|
|
-import cn.iocoder.yudao.module.museum.dal.database.museuminfo.MuseumInfoDO;
|
|
|
import cn.iocoder.yudao.module.museum.dal.database.museummodel.MuseummodelDO;
|
|
|
-import cn.iocoder.yudao.module.museum.controller.admin.museummodel.vo.MuseummodelPageReqVO;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.BufferedOutputStream;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
|
|
|
@Service
|
|
|
public interface MuseummodelService {
|
|
@@ -30,8 +41,10 @@ public interface MuseummodelService {
|
|
|
|
|
|
/**
|
|
|
* 通过标本编号批量导入模型
|
|
|
- * */
|
|
|
- void batchImportModels(String specimenNumber, MultipartFile zipFile);
|
|
|
+ * @param id 用户 id
|
|
|
+ * @param avatarFile 头像文件
|
|
|
+ */
|
|
|
+// String updateUserPhoto(Long id, InputStream avatarFile) throws Exception;
|
|
|
|
|
|
|
|
|
|
|
@@ -61,3 +74,225 @@ public interface MuseummodelService {
|
|
|
PageResult<MuseummodelDO> getMuseumModelPage(MuseummodelPageReqVO pageReqVO);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+// //假设这是一个服务类中的方法,用于导入图片并处理相关业务逻辑(修正版)
|
|
|
+//@Transactional(rollbackFor = Exception.class)
|
|
|
+//public MuseummodelResqVO importImager(MultipartFile file) throws Exception {
|
|
|
+// // 1. 校验文件类型
|
|
|
+// // 检查上传文件的原始文件名是否以.zip结尾
|
|
|
+// if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
|
+// // 如果不是.zip文件,抛出异常,提示上传的文件夹不是ZIP格式
|
|
|
+// throw new Exception("UPLOADER_FOLDER_NOT_ZIP");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 2. 创建临时目录
|
|
|
+// // 创建一个临时文件,并将其转换为目录,用于存放解压后的文件
|
|
|
+// File tempDir = File.createTempFile("user_images", "");
|
|
|
+// tempDir.mkdirs();
|
|
|
+//
|
|
|
+// // 3. 初始化响应对象
|
|
|
+// // 创建一个ImageImportRespVO对象,用于存储处理结果
|
|
|
+// MuseummodelResqVO respVo = new MuseummodelResqVO()
|
|
|
+// .build()
|
|
|
+// // 初始化错误图片列表
|
|
|
+// .setErrorImages(new ArrayList<>())
|
|
|
+// // 初始化失败图片列表
|
|
|
+// .setFailureImages(new ArrayList<>())
|
|
|
+// // 初始化空用户列表
|
|
|
+// .setNullUsers(new ArrayList<>());
|
|
|
+//
|
|
|
+// // 4. 解压并处理ZIP文件
|
|
|
+// try (
|
|
|
+// // 获取上传文件的输入流
|
|
|
+// InputStream inputStream = file.getInputStream();
|
|
|
+// // 创建一个ZIP输入流,用于读取ZIP文件内容
|
|
|
+// ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream)
|
|
|
+// ) {
|
|
|
+// ZipEntry entry;
|
|
|
+// // 遍历ZIP文件中的每个条目
|
|
|
+// while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
|
+// // 检查当前条目是否为非目录条目
|
|
|
+// if (!entry.isDirectory()) {
|
|
|
+// // 检查条目名称是否为指定的名称
|
|
|
+// if ("图片格式正确".equals(entry.getName())) {
|
|
|
+// // 获取当前时间,用于记录图片更新时间
|
|
|
+// String nowTime = LocalDateTime.now().toString();
|
|
|
+// // 解析文件名,获取学生姓名
|
|
|
+// // 假设文件名包含学生姓名,通过截取文件名的一部分来获取
|
|
|
+// String specimenName = entry.getName().substring(0, entry.getName().lastIndexOf("."));
|
|
|
+// // 创建一个新的文件对象,用于存储解压后的文件
|
|
|
+// File newFile = new File(tempDir, entry.getName());
|
|
|
+//
|
|
|
+// // 5. 解压文件
|
|
|
+// try (
|
|
|
+// // 创建一个缓冲输出流,用于将ZIP条目内容写入新文件
|
|
|
+// BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))
|
|
|
+// ) {
|
|
|
+// byte[] buffer = new byte[1024];
|
|
|
+// int len;
|
|
|
+// // 从ZIP输入流中读取数据,并写入新文件
|
|
|
+// while ((len = zipInputStream.read(buffer)) > 0) {
|
|
|
+// bos.write(buffer, 0, len);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 6. 获取业务数据并解析
|
|
|
+// // 调用gettiser方法获取业务数据,这里userNumber未定义,需要根据实际情况传入
|
|
|
+// String result = getClass(specimenNumber);
|
|
|
+// // 创建一个Gson对象,用于解析JSON数据
|
|
|
+// Gson gson = new Gson();
|
|
|
+// // 将获取的JSON字符串解析为JSONObject对象
|
|
|
+// JSONObject jsonObject = gson.fromJson(result, JSONObject.class);
|
|
|
+// // 从JSONObject中获取userInfoSearch对象下的UserInfo数组
|
|
|
+// JSONArray userInfoArray = jsonObject
|
|
|
+// .getJSONObject("userInfoSearch")
|
|
|
+// .getJSONArray("UserInfo");
|
|
|
+//
|
|
|
+// // 7. 处理用户信息
|
|
|
+// if (userInfoArray != null) {
|
|
|
+// // 根据用户编号查找用户信息,这里userService未定义,需要根据实际情况注入
|
|
|
+// AminUser user = MuseummodelService.findspecimenByspecimenNumber((specimenNumber);
|
|
|
+// // 调用PhotoUtil工具类的createFiles方法,将文件内容转换为图片URL,这里PhotoUtil未定义
|
|
|
+// String photoUrl = PhotoUtil.createFiles(Files.readAllBytes(newFile.toPath()));
|
|
|
+// // 调用addFaceByVol方法,处理人脸相关业务,返回处理结果信息
|
|
|
+// String msg = notifyAll(specimenNumber, photoUrl);
|
|
|
+// // 检查处理结果信息是否包含特定关键字
|
|
|
+// if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+// // 如果符合条件,将学生姓名添加到创建成功的图片列表中
|
|
|
+// respVo.getCreateImages().add(specimenName);
|
|
|
+// if (user != null) {
|
|
|
+// // 更新用户的图片更新时间
|
|
|
+// user.setPhotoUpdateTime(nowTime);
|
|
|
+// // 更新用户的图片URL
|
|
|
+// user.setPhotoUrl(photoUrl);
|
|
|
+// // 调用userService的updateUser方法,更新用户信息
|
|
|
+// MuseummodelService.updateUser(user);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // 如果不符合条件,将学生姓名添加到失败图片列表中
|
|
|
+// respVo.getFailureImages().add(specimenName);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // 如果用户信息数组为空,将学生姓名添加到空用户列表中
|
|
|
+// respVo.getNullUsers().add(specimenName);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 8. 返回处理结果
|
|
|
+// return respVo;
|
|
|
+//}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// 假设这是一个服务类中的方法,用于导入图片并处理相关业务逻辑
|
|
|
+//@Transactional(rollbackFor = Exception.class)
|
|
|
+//public ImageImportRespVO importImager(MultipartFile file) throws Exception {
|
|
|
+// // 1. 校验文件类型
|
|
|
+// // 检查上传文件的原始文件名是否以.zip结尾
|
|
|
+// if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
|
+// // 如果不是.zip文件,抛出异常,提示上传的文件夹不是ZIP格式
|
|
|
+// throw new Exception("UPLOADER_FOLDER_NOT_ZIP");
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 2. 创建临时目录
|
|
|
+// // 创建一个临时文件,并将其转换为目录,用于存放解压后的文件
|
|
|
+// File tempDir = File.createTempFile("user_images", "").toFile();
|
|
|
+// tempDir.mkdirs();
|
|
|
+//
|
|
|
+// // 3. 初始化响应对象
|
|
|
+// // 创建一个ImageImportRespVO对象,用于存储处理结果
|
|
|
+// ImageImportRespVO respVo = new ImageImportRespVO()
|
|
|
+// .build()
|
|
|
+// // 初始化错误图片列表
|
|
|
+// .setErrorImages(new ArrayList<>())
|
|
|
+// // 初始化失败图片列表
|
|
|
+// .setFailureImages(new ArrayList<>())
|
|
|
+// // 初始化空用户列表
|
|
|
+// .setNullUsers(new ArrayList<>());
|
|
|
+//
|
|
|
+// // 4. 解压并处理ZIP文件
|
|
|
+// try (
|
|
|
+// // 获取上传文件的输入流
|
|
|
+// InputStream inputStream = file.getInputStream();
|
|
|
+// // 创建一个ZIP输入流,用于读取ZIP文件内容
|
|
|
+// ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream)
|
|
|
+// ) {
|
|
|
+// ZipEntry entry;
|
|
|
+// // 遍历ZIP文件中的每个条目
|
|
|
+// while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
|
+// // 检查当前条目是否为非目录条目
|
|
|
+// if (!entry.isDirectory()) {
|
|
|
+// // 检查条目名称是否为指定的名称
|
|
|
+// if ("图片格式正确".equals(entry.getName())) {
|
|
|
+// // 获取当前时间,用于记录图片更新时间
|
|
|
+// String nowTime = LocalDateTime.now().toString();
|
|
|
+// // 解析文件名,获取学生姓名
|
|
|
+// // 假设文件名包含学生姓名,通过截取文件名的一部分来获取
|
|
|
+// String studentName = entry.getName().substring(0, entry.getName().lastIndexOf("."));
|
|
|
+// // 创建一个新的文件对象,用于存储解压后的文件
|
|
|
+// File newFile = new File(tempDir, entry.getName());
|
|
|
+//
|
|
|
+// // 5. 解压文件
|
|
|
+// try (
|
|
|
+// // 创建一个缓冲输出流,用于将ZIP条目内容写入新文件
|
|
|
+// BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))
|
|
|
+// ) {
|
|
|
+// byte[] buffer = new byte[1024];
|
|
|
+// int len;
|
|
|
+// // 从ZIP输入流中读取数据,并写入新文件
|
|
|
+// while ((len = zipInputStream.read(buffer)) > 0) {
|
|
|
+// bos.write(buffer, 0, len);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 6. 获取业务数据并解析
|
|
|
+// // 调用gettiser方法获取业务数据,这里userNumber未定义,需要根据实际情况传入
|
|
|
+// String result = gettiser(userNumber);
|
|
|
+// // 创建一个Gson对象,用于解析JSON数据
|
|
|
+// Gson gson = new Gson();
|
|
|
+// // 将获取的JSON字符串解析为JSONObject对象
|
|
|
+// JSONObject jsonObject = gson.fromJson(result, JSONObject.class);
|
|
|
+// // 从JSONObject中获取userInfoSearch对象下的UserInfo数组
|
|
|
+// JSONArray userInfoArray = jsonObject
|
|
|
+// .getJSONObject("userInfoSearch")
|
|
|
+// .getJSONArray("UserInfo");
|
|
|
+//
|
|
|
+// // 7. 处理用户信息
|
|
|
+// if (userInfoArray != null) {
|
|
|
+// // 根据用户编号查找用户信息,这里userService未定义,需要根据实际情况注入
|
|
|
+// AminUser user = userService.findUserByUserNumber(userNumber);
|
|
|
+// // 调用PhotoUtil工具类的createFiles方法,将文件内容转换为图片URL,这里PhotoUtil未定义
|
|
|
+// String photoUrl = PhotoUtil.createFiles(Files.readAllBytes(newFile.toPath()));
|
|
|
+// // 调用addFaceByVol方法,处理人脸相关业务,返回处理结果信息
|
|
|
+// String msg = addFaceByVol(userNumber, photoUrl);
|
|
|
+// // 检查处理结果信息是否包含特定关键字
|
|
|
+// if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
+// // 如果符合条件,将学生姓名添加到创建成功的图片列表中
|
|
|
+// respVo.getCreateImages().add(studentName);
|
|
|
+// if (user != null) {
|
|
|
+// // 更新用户的图片更新时间
|
|
|
+// user.setPhotoUpdateTime(nowTime);
|
|
|
+// // 更新用户的图片URL
|
|
|
+// user.setPhotoUrl(photoUrl);
|
|
|
+// // 调用userService的updateUser方法,更新用户信息
|
|
|
+// userService.updateUser(user);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // 如果不符合条件,将学生姓名添加到失败图片列表中
|
|
|
+// respVo.getFailureImages().add(studentName);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// // 如果用户信息数组为空,将学生姓名添加到空用户列表中
|
|
|
+// respVo.getNullUsers().add(studentName);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 8. 返回处理结果
|
|
|
+// return respVo;
|
|
|
+//}
|