xiaofei 10 сар өмнө
parent
commit
f5e1b409f8

+ 3 - 0
paper-library-business/src/main/java/com/qmth/paper/library/business/bean/result/PaperScanTaskDetailResult.java

@@ -1,5 +1,7 @@
 package com.qmth.paper.library.business.bean.result;
 
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
 import io.swagger.annotations.ApiModelProperty;
 
 import java.io.Serializable;
@@ -31,6 +33,7 @@ public class PaperScanTaskDetailResult {
     private int bindCount;
 
     @ApiModelProperty(value = "考生ID")
+    @JsonSerialize(using = ToStringSerializer.class)
     private Long studentId;
 
     public String getStudentName() {

+ 1 - 0
paper-library-business/src/main/java/com/qmth/paper/library/business/service/FileUploadService.java

@@ -13,6 +13,7 @@ public interface FileUploadService {
     FilePathVo uploadFile(File sourceFile, UploadFileEnum uploadFileEnum, String fileName);
 
     FilePathVo uploadFile(MultipartFile file, UploadFileEnum uploadFileEnum, String filePathName);
+    FilePathVo uploadRotateFile(File file, UploadFileEnum uploadFileEnum, String filePathName);
 
     File downloadFile(String path, String filePathName) throws Exception;
 

+ 1 - 1
paper-library-business/src/main/java/com/qmth/paper/library/business/service/PaperScanTaskService.java

@@ -44,5 +44,5 @@ public interface PaperScanTaskService extends IService<PaperScanTask> {
 
     List<PaperScanTask> listByExamId(Long examId);
 
-    void clearSingleStudentData(Long studentId);
+    void clearSingleStudentData(Long paperScanTaskId, Long studentId);
 }

+ 18 - 0
paper-library-business/src/main/java/com/qmth/paper/library/business/service/impl/FileUploadServiceImpl.java

@@ -89,6 +89,24 @@ public class FileUploadServiceImpl implements FileUploadService {
         return null;
     }
 
+    @Override
+    public FilePathVo uploadRotateFile(File file, UploadFileEnum uploadFileEnum, String filePathName) {
+        try {
+            String md5 = DigestUtils.md5Hex(new FileInputStream(file));
+            fileStoreUtil.fileUpload(filePathName, new FileInputStream(file), md5);
+            String type = fileStoreUtil.isOssStore() ? SystemConstant.OSS : SystemConstant.LOCAL;
+            return new FilePathVo(filePathName, uploadFileEnum, type, md5);
+        } catch (Exception e) {
+            log.error(SystemConstant.LOG_ERROR, e);
+            if (e instanceof ApiException) {
+                ResultUtil.error((ApiException) e, e.getMessage());
+            } else {
+                ResultUtil.error(e.getMessage());
+            }
+        }
+        return null;
+    }
+
     /**
      * 获取附件文件
      *

+ 1 - 1
paper-library-business/src/main/java/com/qmth/paper/library/business/service/impl/PaperLibraryServiceImpl.java

@@ -416,7 +416,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
             outputFile = SystemConstant.getFileTempVar(filePathVo.getPath().substring(filePathVo.getPath().lastIndexOf(SystemConstant.ORG_POINT)));
             ImageUtil.rotate(fileUploadService.downloadInputStream(filePathVo.getPath(), filePathVo.getType()), rotate, outputFile);
             if (outputFile.exists()) {
-                fileUploadService.uploadFile(outputFile, filePathVo.getUploadType(), filePathVo.getPath());
+                fileUploadService.uploadRotateFile(outputFile, filePathVo.getUploadType(), filePathVo.getPath());
             }
             return true;
         } catch (Exception e) {

+ 15 - 18
paper-library-business/src/main/java/com/qmth/paper/library/business/service/impl/PaperScanTaskServiceImpl.java

@@ -185,40 +185,37 @@ public class PaperScanTaskServiceImpl extends ServiceImpl<PaperScanTaskMapper, P
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void clearSingleStudentData(Long studentId) {
+    public void clearSingleStudentData(Long paperScanTaskId, Long studentId) {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         ExamStudent student = examStudentService.getById(studentId);
-        if(Objects.isNull(student)) {
+        if (Objects.isNull(student)) {
             throw ExceptionResultEnum.ERROR.exception("考生不存在");
         }
 
         //需要删除的图片集合
         LambdaQueryWrapper<PaperLibrary> queryWrapper = new LambdaQueryWrapper<>();
-        queryWrapper.eq(PaperLibrary::getStudentId, studentId);
+        queryWrapper.eq(PaperLibrary::getPaperScanTaskId, paperScanTaskId).eq(PaperLibrary::getStudentId, studentId);
 
         //更新任务的扫描考生数、扫描张数
         List<PaperLibrary> paperLibraryList = paperLibraryService.list(queryWrapper);
-        List<Long> paperScanTaskIds = paperLibraryList.stream().map(PaperLibrary::getPaperScanTaskId).distinct().collect(Collectors.toList());
-        int count;
-        PaperScanTask task;
-        for (Long scanTaskId : paperScanTaskIds) {
-            count = (int) paperLibraryList.stream().filter(paperLibrary -> paperLibrary.getPaperScanTaskId().equals(scanTaskId)).count();
-            task = this.getById(scanTaskId);
-            if (!Objects.isNull(task)) {
-                task.setScanCount(Math.max((task.getScanCount() - count), 0));
-                task.setScanStudentCount(Math.max(task.getScanStudentCount() - 1, 0));
-                task.setUpdateId(sysUser.getId());
-                task.setUpdateTime(System.currentTimeMillis());
-                this.updateById(task);
-            }
+        if(CollectionUtils.isEmpty(paperLibraryList)){
+            return;
+        }
+
+        PaperScanTask task = this.getById(paperScanTaskId);
+        if (!Objects.isNull(task)) {
+            task.setScanCount(Math.max((task.getScanCount() - paperLibraryList.size()), 0));
+            task.setScanStudentCount(Math.max(task.getScanStudentCount() - 1, 0));
+            task.setUpdateId(sysUser.getId());
+            task.setUpdateTime(System.currentTimeMillis());
+            this.updateById(task);
         }
 
         //删除考生的扫描数据
         paperLibraryService.remove(queryWrapper);
 
         //重置考生的扫描张数
-        student.setBindCount(0);
-        examStudentService.updateById(student);
+        examStudentService.updateBindCount(studentId);
 
         //删除考生的图片数据
         for (PaperLibrary paperLibrary : paperLibraryList) {

+ 1 - 1
paper-library-common/src/main/java/com/qmth/paper/library/common/util/ImageUtil.java

@@ -94,7 +94,7 @@ public class ImageUtil {
             if (rotate == 0) {
                 Thumbnails.of(inputStream).toFile(outFile);
             } else {
-                Thumbnails.of(inputStream).scale(0.8).rotate(rotate).toFile(outFile);
+                Thumbnails.of(inputStream).scale(1).rotate(rotate).outputQuality(1).toFile(outFile);
             }
         } catch (IOException e) {
             e.printStackTrace();

+ 3 - 2
paper-library/src/main/java/com/qmth/paper/library/api/PaperScanTaskController.java

@@ -60,8 +60,9 @@ public class PaperScanTaskController {
     @ApiOperation(value = "单个考生清除数据")
     @RequestMapping(value = "/clear_single_data", method = RequestMethod.POST)
     @ApiResponses({ @ApiResponse(code = 200, message = "删除成功", response = EditResult.class) })
-    public Result clearScanSingleData(@ApiParam(value = "考生ID", required = true) @RequestParam Long studentId) {
-        paperScanTaskService.clearSingleStudentData(studentId);
+    public Result clearScanSingleData(@ApiParam(value = "扫描任务ID", required = true) @RequestParam Long paperScanTaskId,
+                                      @ApiParam(value = "考生ID", required = true) @RequestParam Long studentId) {
+        paperScanTaskService.clearSingleStudentData(paperScanTaskId, studentId);
         return ResultUtil.ok();
     }
 }

+ 3 - 0
paper-library/src/main/resources/db-log/xf.sql

@@ -54,3 +54,6 @@ INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence
 UPDATE `sys_privilege` SET `related` = '266,278' WHERE (`id` = '261');
 UPDATE `sys_privilege` SET `related` = '266,278' WHERE (`id` = '262');
 UPDATE `sys_privilege` SET `related` = '266,278' WHERE (`id` = '263');
+
+INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `related`, `enable`, `default_auth`, `front_display`) VALUES ('253', '清除学生数据', 'ClearStudentScanData', 'LINK', '244', '6', 'AUTH', '254', '1', '0', '1');
+INSERT INTO `sys_privilege` (`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `enable`, `default_auth`, `front_display`) VALUES ('254', '清除学生数据接口', '/api/admin/paper/scan_task/clear_single_data', 'URL', '244', '4', 'AUTH', '1', '1', '1');