Browse Source

10.26,基本

Crazy 8 months ago
parent
commit
541a38a97e

+ 8 - 28
yudao-module-md/yudao-module-md-biz/src/main/java/cn/iocoder/yudao/module/md/controller/admin/AcsController.java

@@ -237,11 +237,10 @@ public class AcsController {
             @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
     })
    @PreAuthorize("@ss.hasPermission('system:users-info-with-image:import')")
-    public CommonResult<importResponse> importData(@RequestParam("excelFile") MultipartFile excelFile,
-                                                   @RequestParam("imageFile") MultipartFile imageFile,
-                                                   @RequestParam(value = "updateSupport", required = false, defaultValue = "true") Boolean updateSupport) {
+    public CommonResult<importResponse> importData( @RequestParam(value = "excelFile", required = false) MultipartFile excelFile,
+                                                    @RequestParam(value = "imageFile", required = false) MultipartFile imageFile) {
         try {
-            importResponse response = acsService.importData(excelFile, imageFile, updateSupport);
+            importResponse response = acsService.importData(excelFile, imageFile);
             System.out.println("导入结果"+response);
             return CommonResult.success(response);
         } catch (Exception e) {
@@ -250,15 +249,15 @@ public class AcsController {
     }
 
 
-    @PostMapping("/import-userData")
-    @Operation(summary = "用户自己上传(可添加信息也可上传照片)")
+    @PostMapping("/import-selfData")
+    @Operation(summary = "用户自己上传(考勤信息也可上传照片)")
     @Parameters({
             @Parameter(name = "imageFile", description = "照片", required = true),
     })
     @PreAuthorize("@ss.hasPermission('system:user-data:import')")
-    public CommonResult<String> importUserData(@RequestParam("imageFile") MultipartFile imageFile) {
+    public CommonResult<String> importUserData(@RequestParam("photoUrl") String photoUrl) {
         try {
-            String result = acsService.addSelfImage(imageFile);
+            String result = acsService.addSelfImage(photoUrl);
             return CommonResult.success(result);
         } catch (Exception e) {
             return CommonResult.error(500, "导入过程中发生错误: " + e.getMessage());
@@ -266,6 +265,7 @@ public class AcsController {
     }
 
 
+
     @PostMapping("/teacher-updateUserImage")
     @Operation(summary = "教师更新学生图片")
     @Parameters({
@@ -284,26 +284,6 @@ public class AcsController {
     }
 
 
-
-
-    @PostMapping("/直接下发人员和人脸")
-    @Operation(summary = "lsq")
-    @Parameters({
-            @Parameter(name = "excelFile", description = "Excel 文件", required = true),
-            @Parameter(name = "imageFile", description = "压缩包文件", required = true),
-            @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true")
-    })
-    public CommonResult<importResponse> test(@RequestParam("excelFile") MultipartFile excelFile,
-                                           @RequestParam("imageFile") MultipartFile imageFile,
-                                           @RequestParam(value = "updateSupport", required = false, defaultValue = "true") Boolean updateSupport) {
-        try {
-            importResponse response = acsService.testData(excelFile, imageFile, updateSupport);
-            return CommonResult.success(response);
-        } catch (Exception e) {
-            return CommonResult.error(500, "导入过程中发生错误: " + e.getMessage());
-        }
-    }
-
     //考勤分页
     @GetMapping("/page")
     @Operation(summary = "获得学生考勤记录分页")

+ 54 - 153
yudao-module-md/yudao-module-md-biz/src/main/java/cn/iocoder/yudao/module/md/service/AcsService.java

@@ -278,58 +278,60 @@ public class AcsService {
 
     //用户添加自己的照片(也可以对考勤机那添加用户信息照片或更新照片)
     @Transactional(rollbackFor = Exception.class) //
-    public String addSelfImage(MultipartFile image) throws Exception {
-        if (isValidImageName(image.getOriginalFilename()).equals("照片格式正确")) {
+    public String addSelfImage(String photoUrl) throws Exception {
             Long loginId = SecurityFrameworkUtils.getLoginUserId();
             AdminUserDO user = userService.getUser(loginId);
-            //创建临时文件目录
-            File tempDir = Files.createTempDirectory("user_image").toFile();
-             try {
-                 File newFile =new File(tempDir,image.getOriginalFilename());
-                 //将内容写入
-                 image.transferTo(newFile);
-                 String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
-                 user.setPhotoUrl(photoUrl);
-                 String userNumber = user.getUserNumber();
-
-                 String result = getUser(userNumber);
-                 Gson gson = new Gson();
-                 JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
-                 JsonArray userInfoArray = jsonObject
-                         .getAsJsonObject("UserInfoSearch")
-                         .getAsJsonArray("UserInfo");
-
-                 if (userInfoArray != null) {
-                     addFaceByUrl(userNumber, user.getPhotoUrl());
+
+             String userNumber = user.getUserNumber();
+
+             //考勤机
+             String result = getUser(userNumber);
+             Gson gson = new Gson();
+             JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
+             JsonArray userInfoArray = jsonObject
+                     .getAsJsonObject("UserInfoSearch")
+                     .getAsJsonArray("UserInfo");
+
+             if (userInfoArray != null) {//考勤机里有用户
+                 String msg =  addFaceByUrl(userNumber,photoUrl);
+                 if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
+                     return "更新人脸失败";
                  } else {
-                     //确保在执行完增加用户后执行增加人脸
-                     CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
-                         try {
-                             addUser(userNumber, user.getNickname());
-                         } catch (JSONException e) {
-                             throw new RuntimeException(e);
-                         } catch (UnsupportedEncodingException e) {
-                             throw new RuntimeException(e);
-                         } catch (InterruptedException e) {
-                             throw new RuntimeException(e);
-                         }
-                     });
-                     userFuture.thenRun(() -> {
-                         try {
-                             addFaceByUrl(userNumber, photoUrl);
-                         } catch (JSONException e) {
-                             throw new RuntimeException(e);
-                         }
-                     });
-                     return "添加用户并且增加照片成功";
+                     if (user!=null) {
+                         user.setPhotoUrl(photoUrl);
+                         userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
+                     }
+                     return "更新人脸成功";
                  }
-             }finally {
-                 FileUtils.deleteDirectory(tempDir);
+             } else {//考勤及里面没用户
+                 //确保在执行完增加用户后执行增加人脸
+                 CompletableFuture<Void> userFuture = CompletableFuture.runAsync(() -> {
+                     try {
+                         addUser(userNumber, user.getNickname());
+                     } catch (JSONException e) {
+                         throw new RuntimeException(e);
+                     } catch (UnsupportedEncodingException e) {
+                         throw new RuntimeException(e);
+                     } catch (InterruptedException e) {
+                         throw new RuntimeException(e);
+                     }
+                 });
+                 userFuture.thenRun(() -> {
+                     try {
+                      String msg = addFaceByUrl(userNumber, photoUrl);
+                         if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
+                         } else {
+                             if (user!=null) {
+                                 user.setPhotoUrl(photoUrl);
+                                 userService.updateUser((BeanUtils.toBean(user, UserSaveReqVO.class)));
+                             }
+                         }
+                     } catch (JSONException e) {
+                         throw new RuntimeException(e);
+                     }
+                 });
+                 return "添加考勤用户并且增加照片成功";
              }
-            return "更新照片成功";
-        }else{
-            return "照片格式有问题";
-        }
     }
 
 
@@ -368,7 +370,7 @@ public class AcsService {
 
     //批量导入用户信息
     @Transactional(rollbackFor = Exception.class) // 添加事务,异常则回滚所有导入
-    public attendanceImportRespVO importUserList(List<attendanceImportExcelVO> importUsers, boolean isUpdateSupport) {
+    public attendanceImportRespVO importUserList(List<attendanceImportExcelVO> importUsers) {
 
         attendanceImportRespVO respVO = attendanceImportRespVO.builder().createUsernames(new ArrayList<>())
                 .updateUsernames(new ArrayList<>()).failureUsernames(new LinkedHashMap<>()).build();
@@ -439,7 +441,7 @@ public class AcsService {
                                 AdminUserDO user = userService.findUserByUserNumber(userNumber);
                                 String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
                                 //给对应学号的人的照片添加
-                                String msg = addFaceByUrl(user.getUserNumber(), photoUrl);
+                                String msg = addFaceByUrl(userNumber, photoUrl);
                                 if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
                                     respVO.getFailureImages().add(studentName);//添加失败
                                 } else {
@@ -464,84 +466,7 @@ public class AcsService {
     }
 
 
-    //直接导入用户人脸
-    public String testImages(MultipartFile file) throws Exception {
-        // 校验文件类型
-        if (!file.getOriginalFilename().endsWith(".zip")) {
-            throw exception(UPLOADED_FOLDER_CANNOT_EMPTY);
-        }
-        // 创建临时目录存放解压后的文件
-        File tempDir = Files.createTempDirectory("users_images").toFile();
-        List<String> successUsers =new LinkedList<>();
-        List<String> failUsers =new LinkedList<>();
-        List<String> nullUsers =new LinkedList<>();
-        List<String> errorImages =new LinkedList<>();
-        try (InputStream inputStream = file.getInputStream();
-             ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(inputStream)) {
-            ZipEntry entry;
-            while ((entry = zipInputStream.getNextZipEntry()) != null) {
-                if (!entry.isDirectory()) {
-                    //看名字
-                    if (isValidImageName(entry.getName()).equals("照片格式正确")) {
-                        System.out.println(entry.getName());
-                        //获取去除后缀名的文件名,需要设置成学号
-                        String userNumber = entry.getName().substring(0, entry.getName().lastIndexOf('-'));
-                        String studentName = entry.getName().substring(entry.getName().lastIndexOf('-') + 1, entry.getName().lastIndexOf('.'));
-//                        System.out.println("学号:" + userNumber);
-//                        System.out.println("学生名字:" + studentName);
-                        File newFile = new File(tempDir, entry.getName());
-                        // 进行解压
-                        try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
-                            byte[] buffer = new byte[1024];
-                            int len;
-                            while ((len = zipInputStream.read(buffer)) > 0) {
-                                bos.write(buffer, 0, len);
-                            }
-                        }
-                        String result =getUser(userNumber);
-                        //用户不为空,为用户添加人脸
-                            Gson gson = new Gson();
-                            JsonObject jsonObject = gson.fromJson(result, JsonObject.class);
-
-                            JsonArray userInfoArray = jsonObject
-                                    .getAsJsonObject("UserInfoSearch")
-                                    .getAsJsonArray("UserInfo");
-                            if (userInfoArray!=null) {
-                                String photoUrl = fileApi.createFile(Files.readAllBytes(newFile.toPath()));
-                                //给对应学号的人的照片添加
-                                String msg = addFaceByUrl(userNumber, photoUrl);
-                                //System.out.println("数据"+msg);
-                                if (msg.contains("下发人脸成功") && msg.contains("但是有异常情况")) {
-                                    failUsers.add(studentName);
-                                } else {
-                                    successUsers.add(studentName);
-                                }
-                            } else{
-                                nullUsers.add(studentName);//添加找不到的用户
-                        }
-                    }
-                }
-            }
-        }
-        // 清理临时文件
-        FileUtils.deleteDirectory(tempDir);
-        return "添加照片成功的用户{"
-                +successUsers+
-                "}"+
-                "添加照片失败的用户{"
-                +failUsers+
-                "}"+
-                "不存在的用户{"+
-                nullUsers+
-                "}"+
-                "照片格式错误{"+
-                errorImages+
-                "}";
-
-    }
-
-
-    // 检查多个图片名称格式
+    // 检查图片名称格式
     private String isValidImageName(String imageName) {
         if (imageName == null || imageName.trim().isEmpty()) {
             return "照片为空"; // 如果照片名称为空,返回提示信息
@@ -552,16 +477,15 @@ public class AcsService {
         return "照片格式正确"; // 如果格式正确,返回确认消息
     }
 
-
     private attendanceImportRespVO importRespVO;
     private imageImportRespVO imageImportResult;
     @Transactional(rollbackFor = Exception.class) // 事务管理
-    public importResponse importData(MultipartFile excelFile, MultipartFile imageFile, boolean updateSupport) throws Exception {
+    public importResponse importData(MultipartFile excelFile, MultipartFile imageFile) throws Exception {
         importResponse response = importResponse.builder().build();
         // 1. 导入用户信息
         if (excelFile!=null){
             List<attendanceImportExcelVO> list = ExcelUtils.read(excelFile, attendanceImportExcelVO.class);
-            importRespVO = importUserList(list, updateSupport);
+            importRespVO = importUserList(list);
             System.out.println("用户信息导入结果: " + importRespVO);
         }else {
             importRespVO=null;
@@ -581,28 +505,5 @@ public class AcsService {
 
 
 
-    @Transactional(rollbackFor = Exception.class) // 是先插入的
-    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);
-            importRespVO = importUserList(list, updateSupport);
-            System.out.println("用户信息导入结果: " + importRespVO);
-        }else {
-            importRespVO=null;
-        }
-        // 2. 导入图片
-        if (imageFile!=null){
-            imageImportResult = importImages(imageFile);
-            System.out.println("图片导入结果: " + imageImportResult);
-        }else {
-            imageImportResult=null;
-        }
-        response.setImageImportResult(imageImportResult);
-        response.setUserImportResult(importRespVO);
-
-        return response;
-    }
 
 }

+ 1 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dept/DeptController.java

@@ -97,6 +97,7 @@ public class DeptController {
 
     @GetMapping("/GetUserDept")
     @Operation(summary = "获得登录人员工作间信息")
+    @PreAuthorize("@ss.hasPermission('system:dept:selfQuery')")
     public CommonResult<DeptRespVO> getUserDept() {
         // 获取部门信息
         DeptDO dept = deptService.getUserDept();

+ 0 - 2
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/studentAttendance/vo/weekendAttendanceResVO.java

@@ -21,6 +21,4 @@ public class weekendAttendanceResVO {
     @Schema(description = "正常人员名字列表")
     private List<String> normalNameList;
 
-
-
 }