|
@@ -10,6 +10,8 @@ import cn.iocoder.yudao.module.infra.api.config.ConfigApi;
|
|
|
import cn.iocoder.yudao.module.infra.api.file.FileApi;
|
|
|
import cn.iocoder.yudao.module.md.controller.admin.vo.attendanceImportExcelVO;
|
|
|
import cn.iocoder.yudao.module.md.controller.admin.vo.attendanceImportRespVO;
|
|
|
+import cn.iocoder.yudao.module.md.controller.admin.vo.imageImportRespVO;
|
|
|
+import cn.iocoder.yudao.module.md.controller.admin.vo.importResponse;
|
|
|
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
import cn.iocoder.yudao.module.system.controller.admin.user.vo.user.UserSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
|
@@ -402,13 +404,16 @@ public class AcsService {
|
|
|
|
|
|
//插入照片到考勤用户,成功后再插入到对应用户的photoUrl(需要先有用户信息)
|
|
|
@Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
|
|
|
- public String importImages(MultipartFile file) throws Exception {
|
|
|
+ public imageImportRespVO importImages(MultipartFile file) throws Exception {
|
|
|
// 校验文件类型
|
|
|
if (!file.getOriginalFilename().endsWith(".zip")) {
|
|
|
throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
|
|
|
}
|
|
|
// 创建临时目录存放解压后的文件
|
|
|
File tempDir = Files.createTempDirectory("user_images").toFile();
|
|
|
+ imageImportRespVO respVO = imageImportRespVO.builder().createImages(new ArrayList<>())
|
|
|
+ .updateImages(new ArrayList<>()).failureImages(new ArrayList<>()).errorImages(new ArrayList<>()).nullUsers(new ArrayList<>()).build();
|
|
|
+
|
|
|
List<String> successUsers =new LinkedList<>();
|
|
|
List<String> failUsers =new LinkedList<>();
|
|
|
List<String> nullUsers =new LinkedList<>();
|
|
@@ -448,37 +453,26 @@ public class AcsService {
|
|
|
//给对应学号的人的照片添加
|
|
|
String msg = addFaceByUrl(user.getUserNumber(), photoUrl);
|
|
|
if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
|
|
|
- failUsers.add(studentName);
|
|
|
+ respVO.getFailureImages().add(studentName);//添加失败
|
|
|
} else {
|
|
|
- successUsers.add(studentName);
|
|
|
+ respVO.getCreateImages().add(studentName);//添加成功
|
|
|
if (user!=null) {
|
|
|
user.setPhotoUrl(photoUrl);
|
|
|
userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- nullUsers.add(studentName);
|
|
|
+ respVO.getNullUsers().add(studentName);//照片用户不存在
|
|
|
}
|
|
|
}else{
|
|
|
- errorImages.add(entry.getName());
|
|
|
+ respVO.getErrorImages().add(entry.getName());//照片格式错误
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 清理临时文件
|
|
|
FileUtils.deleteDirectory(tempDir);
|
|
|
- return "添加照片成功的用户{"
|
|
|
- +successUsers+
|
|
|
- "}"+
|
|
|
- "添加照片失败的用户{"
|
|
|
- +failUsers+
|
|
|
- "}"+
|
|
|
- "不存在的用户{"+
|
|
|
- nullUsers+
|
|
|
- "}"+
|
|
|
- "照片格式错误{"+
|
|
|
- errorImages+
|
|
|
- "}";
|
|
|
+ return respVO;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -572,9 +566,10 @@ public class AcsService {
|
|
|
|
|
|
|
|
|
private attendanceImportRespVO importRespVO;
|
|
|
- private String imageImportResult;
|
|
|
+ private imageImportRespVO imageImportResult;
|
|
|
@Transactional(rollbackFor = Exception.class) // 事务管理
|
|
|
- public String importData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
+ public importResponse importData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
+ importResponse response = importResponse.builder().build();
|
|
|
// 1. 导入用户信息
|
|
|
if (excelFile!=null){
|
|
|
List<attendanceImportExcelVO> list = ExcelUtils.read(excelFile, attendanceImportExcelVO.class);
|
|
@@ -585,20 +580,22 @@ public class AcsService {
|
|
|
}
|
|
|
// 2. 导入图片
|
|
|
if (imageFile!=null){
|
|
|
- imageImportResult = testImages(imageFile);
|
|
|
+ imageImportResult = importImages(imageFile);
|
|
|
System.out.println("图片导入结果: " + imageImportResult);
|
|
|
}else {
|
|
|
- imageImportResult="为传入照片信息";
|
|
|
+ imageImportResult=null;
|
|
|
}
|
|
|
+ response.setImageImportResult(imageImportResult);
|
|
|
+ response.setUserImportResult(importRespVO);
|
|
|
|
|
|
- return importRespVO+
|
|
|
- imageImportResult;
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) // 是先插入的
|
|
|
- public String testData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
+ public importResponse testData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
|
|
|
+ importResponse response = importResponse.builder().build();
|
|
|
// 1. 导入用户信息
|
|
|
if (excelFile!=null){
|
|
|
List<attendanceImportExcelVO> list = ExcelUtils.read(excelFile, attendanceImportExcelVO.class);
|
|
@@ -612,11 +609,12 @@ public class AcsService {
|
|
|
imageImportResult = importImages(imageFile);
|
|
|
System.out.println("图片导入结果: " + imageImportResult);
|
|
|
}else {
|
|
|
- imageImportResult="为传入照片信息";
|
|
|
+ imageImportResult=null;
|
|
|
}
|
|
|
+ response.setImageImportResult(imageImportResult);
|
|
|
+ response.setUserImportResult(importRespVO);
|
|
|
|
|
|
- return importRespVO+
|
|
|
- imageImportResult;
|
|
|
+ return response;
|
|
|
}
|
|
|
|
|
|
}
|