|
@@ -15,6 +15,9 @@ import cn.iocoder.yudao.module.md.controller.admin.vo.UserImportExcelVO;
|
|
import cn.iocoder.yudao.module.md.controller.admin.vo.UserImportRespVO;
|
|
import cn.iocoder.yudao.module.md.controller.admin.vo.UserImportRespVO;
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
|
|
+import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
|
import com.sun.jna.Native;
|
|
import com.sun.jna.Native;
|
|
import org.apache.tomcat.util.http.fileupload.FileUtils;
|
|
import org.apache.tomcat.util.http.fileupload.FileUtils;
|
|
import org.json.JSONException;
|
|
import org.json.JSONException;
|
|
@@ -314,20 +317,28 @@ public class AcsService {
|
|
// AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername());
|
|
// AdminUserDO existUser = userMapper.selectByUsername(importUser.getUsername());
|
|
// if (existUser == null) {
|
|
// if (existUser == null) {
|
|
// 异步添加用户信息
|
|
// 异步添加用户信息
|
|
|
|
+ AdminUserDO user = userService.findUserByUserNumber(importUser.getEmployeeNo());
|
|
CompletableFuture<Void> addUserFuture = CompletableFuture.runAsync(() -> {
|
|
CompletableFuture<Void> addUserFuture = CompletableFuture.runAsync(() -> {
|
|
try {
|
|
try {
|
|
- UserManage.addUserInfo(lUserID, importUser.getEmployeeNo(), importUser.getName());
|
|
|
|
-
|
|
|
|
|
|
+ //用户名称与那users表里的相同
|
|
|
|
+ if (user.getNickname().equals(importUser.getName())) {
|
|
|
|
+ UserManage.addUserInfo(lUserID, user.getUserNumber(), user.getNickname());
|
|
|
|
+ System.out.println("添加用户成功");
|
|
|
|
+ }
|
|
} catch (UnsupportedEncodingException | InterruptedException | JSONException e) {
|
|
} catch (UnsupportedEncodingException | InterruptedException | JSONException e) {
|
|
throw new RuntimeException("添加用户信息失败: " + e.getMessage(), e);
|
|
throw new RuntimeException("添加用户信息失败: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- // 在用户信息添加成功后添加人脸
|
|
|
|
|
|
+ // 在用户信息添加成功后添加人脸,人脸照片通过学号去找
|
|
addUserFuture.thenRun(() -> {
|
|
addUserFuture.thenRun(() -> {
|
|
try {
|
|
try {
|
|
- FaceManage.addFaceByUrl(lUserID, importUser.getEmployeeNo(), importUser.getFaceURL());
|
|
|
|
- System.out.println("照片路由"+importUser.getFaceURL());
|
|
|
|
|
|
+ String photoUrl =user.getPhotoUrl();
|
|
|
|
+ //照片不为空
|
|
|
|
+ if ( photoUrl!=null){
|
|
|
|
+ FaceManage.addFaceByUrl(lUserID, user.getUserNumber(), photoUrl);
|
|
|
|
+ System.out.println("照片路由"+photoUrl);
|
|
|
|
+ }
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
throw new RuntimeException("添加人脸失败: " + e.getMessage(), e);
|
|
throw new RuntimeException("添加人脸失败: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
@@ -352,6 +363,9 @@ public class AcsService {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private AdminUserService userService;
|
|
|
|
+
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
public String importImages(MultipartFile file) throws Exception {
|
|
public String importImages(MultipartFile file) throws Exception {
|
|
// 校验文件类型
|
|
// 校验文件类型
|
|
@@ -364,6 +378,11 @@ public class AcsService {
|
|
ZipEntry entry;
|
|
ZipEntry entry;
|
|
while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
while ((entry = zipInputStream.getNextEntry()) != null) {
|
|
if (!entry.isDirectory()) {
|
|
if (!entry.isDirectory()) {
|
|
|
|
+
|
|
|
|
+ //获取去除后缀名的文件名,需要设置成学号
|
|
|
|
+ String newFileName = entry.getName().substring(0, entry.getName().lastIndexOf('.'));
|
|
|
|
+ System.out.println("文件名:"+newFileName);
|
|
|
|
+
|
|
File newFile = new File(tempDir, entry.getName());
|
|
File newFile = new File(tempDir, entry.getName());
|
|
// 进行解压
|
|
// 进行解压
|
|
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
|
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
|
@@ -373,37 +392,30 @@ public class AcsService {
|
|
bos.write(buffer, 0, len);
|
|
bos.write(buffer, 0, len);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ File[] imageFiles = tempDir.listFiles();
|
|
|
|
+ if (imageFiles != null) {
|
|
|
|
+ for (File imageFile : imageFiles) {
|
|
|
|
+ String imageName = imageFile.getName();
|
|
|
|
+ if (!isValidImageName(imageName)) {
|
|
|
|
+ // 如果不符合格式,抛出异常或记录日志
|
|
|
|
+ System.err.println("无效的图片格式: " + imageName);
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 上传文件并获取 URL
|
|
|
|
+ AdminUserDO user = userService.findUserByUserNumber(newFileName);
|
|
|
|
+ String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
|
|
|
|
+ user.setPhotoUrl(photoUrl);
|
|
|
|
+ userService.updateUser( (BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
|
+ System.out.println("照片路径: " + photoUrl);
|
|
|
|
+ //给对应学号的人的照片添加
|
|
|
|
+ addFaceByUrl(newFileName,photoUrl);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ System.out.println(111111);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // 处理每个图片文件
|
|
|
|
- File[] imageFiles = tempDir.listFiles();
|
|
|
|
- if (imageFiles != null) {
|
|
|
|
- for (File imageFile : imageFiles) {
|
|
|
|
- String imageName = imageFile.getName();
|
|
|
|
- if (!isValidImageName(imageName)) {
|
|
|
|
- // 如果不符合格式,抛出异常或记录日志
|
|
|
|
- System.err.println("无效的图片格式: " + imageName);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // TODO 这里根据图片名称获取对应的学生信息,然后更新学生信息,并且将这些信息下发到机器
|
|
|
|
- // 查询方法我先不写了
|
|
|
|
-// AdminUserRespDTO user = adminUserApi.getUser(imageName);
|
|
|
|
-
|
|
|
|
- String imagePath = fileApi.createFile(Files.readAllBytes(imageFile.toPath()));
|
|
|
|
-
|
|
|
|
- // user.setImagePath(imagePath); TODO 插入新的人脸图片路径
|
|
|
|
- // 更新标本信息中的图片路径
|
|
|
|
-
|
|
|
|
- // TODO 更新信息 adminUserApi.updateUser(specimenInfo);
|
|
|
|
-
|
|
|
|
- // TODO 在这一步就可以导入人脸信息了 addFaceByUrl(user.getSudentId,imagePath)
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// 清理临时文件
|
|
// 清理临时文件
|
|
FileUtils.deleteDirectory(tempDir);
|
|
FileUtils.deleteDirectory(tempDir);
|
|
return "导入成功";
|
|
return "导入成功";
|
|
@@ -425,7 +437,7 @@ public class AcsService {
|
|
public void importData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
public void importData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
|
|
|
// TODO 这里用的字段太少了,下午和晚上要把字段完善,能够导入
|
|
// TODO 这里用的字段太少了,下午和晚上要把字段完善,能够导入
|
|
- // 1. 导入标本
|
|
|
|
|
|
+ // 1. 导入用户信息
|
|
List<UserImportExcelVO> list = ExcelUtils.read(excelFile, UserImportExcelVO.class);
|
|
List<UserImportExcelVO> list = ExcelUtils.read(excelFile, UserImportExcelVO.class);
|
|
UserImportRespVO importRespVO = importUserList(list, updateSupport);
|
|
UserImportRespVO importRespVO = importUserList(list, updateSupport);
|
|
|
|
|
|
@@ -433,8 +445,8 @@ public class AcsService {
|
|
String imageImportResult = importImages(imageFile);
|
|
String imageImportResult = importImages(imageFile);
|
|
|
|
|
|
// 可以根据需要记录导入结果
|
|
// 可以根据需要记录导入结果
|
|
- System.out.println("标本导入结果: " + importRespVO);
|
|
|
|
- System.out.println("标本图片导入结果: " + imageImportResult);
|
|
|
|
|
|
+ System.out.println("用户信息导入结果: " + importRespVO);
|
|
|
|
+ System.out.println("图片导入结果: " + imageImportResult);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|