Преглед на файлове

扫描任务管理,清除单个考生的扫描数据

haogh преди 10 месеца
родител
ревизия
aa178aa2eb

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

@@ -30,6 +30,9 @@ public class PaperScanTaskDetailResult {
     @ApiModelProperty(value = "绑定张数")
     private int bindCount;
 
+    @ApiModelProperty(value = "考生ID")
+    private Long studentId;
+
     public String getStudentName() {
         return studentName;
     }
@@ -85,4 +88,12 @@ public class PaperScanTaskDetailResult {
     public void setBindCount(int bindCount) {
         this.bindCount = bindCount;
     }
+
+    public Long getStudentId() {
+        return studentId;
+    }
+
+    public void setStudentId(Long studentId) {
+        this.studentId = studentId;
+    }
 }

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

@@ -43,4 +43,6 @@ public interface PaperScanTaskService extends IService<PaperScanTask> {
     void updatePaperScanTask(Long examId, RecognitionTypeEnum recognitionType, StoreTypeEnum storeType, List<ExamStudent> examStudentList, TBTask tbTask);
 
     List<PaperScanTask> listByExamId(Long examId);
+
+    void clearSingleStudentData(Long studentId);
 }

+ 55 - 0
paper-library-business/src/main/java/com/qmth/paper/library/business/service/impl/PaperScanTaskServiceImpl.java

@@ -1,5 +1,7 @@
 package com.qmth.paper.library.business.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -7,6 +9,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.paper.library.business.bean.result.PaperScanTaskDetailResult;
 import com.qmth.paper.library.business.bean.result.PaperScanTaskResult;
+import com.qmth.paper.library.business.bean.vo.FilePathVo;
 import com.qmth.paper.library.business.entity.ExamCourse;
 import com.qmth.paper.library.business.entity.PaperLibrary;
 import com.qmth.paper.library.business.entity.PaperScanTask;
@@ -175,4 +178,56 @@ public class PaperScanTaskServiceImpl extends ServiceImpl<PaperScanTaskMapper, P
         return this.list(queryWrapper);
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void clearSingleStudentData(Long studentId) {
+        SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
+        ExamStudent student = examStudentService.getById(studentId);
+        if(Objects.isNull(student)) {
+            throw ExceptionResultEnum.ERROR.exception("考生不存在");
+        }
+
+        //需要删除的图片集合
+        LambdaQueryWrapper<PaperLibrary> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.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);
+            }
+        }
+
+        //删除考生的扫描数据
+        paperLibraryService.remove(queryWrapper);
+
+        //重置考生的扫描张数
+        student.setBindCount(0);
+        examStudentService.updateById(student);
+
+        //删除考生的图片数据
+        for (PaperLibrary paperLibrary : paperLibraryList) {
+            try {
+                List<FilePathVo> filePathVoList = JSON.parseArray(paperLibrary.getPath(), FilePathVo.class);
+                for (FilePathVo filePathVo : filePathVoList) {
+                    fileStoreUtil.deleteFile(filePathVo.getPath());
+                }
+            } catch (Exception e) {
+                log.error("文件删除失败" + e.getMessage());
+            }
+        }
+
+    }
+
+
 }

+ 2 - 1
paper-library-business/src/main/resources/mapper/PaperScanTaskMapper.xml

@@ -40,7 +40,8 @@
             es.course_name,
             es.teacher,
             es.teach_class,
-            es.bind_count
+            es.bind_count,
+            es.id studentId
         FROM
             paper_scan_task pst
                  JOIN

+ 8 - 0
paper-library/src/main/java/com/qmth/paper/library/api/PaperScanTaskController.java

@@ -56,4 +56,12 @@ public class PaperScanTaskController {
         paperScanTaskService.clearScanData(paperScanTaskId);
         return ResultUtil.ok();
     }
+
+    @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);
+        return ResultUtil.ok();
+    }
 }

+ 6 - 0
paper-library-business/src/main/resources/db/log/hgh_update_log.sql → paper-library/src/main/resources/db-log/hgh_update_log.sql

@@ -52,4 +52,10 @@ INSERT INTO `sys_privilege`(`id`, `name`, `url`, `type`, `parent_id`, `sequence`
 INSERT INTO `sys_privilege`(`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `related`, `enable`, `default_auth`, `front_display`) VALUES (288, '查看图片', '/api/admin/paper/picture/list_student_picture', 'URL', 280, 1, 'AUTH', NULL, 1, 1, 1);
 INSERT INTO `sys_privilege`(`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `related`, `enable`, `default_auth`, `front_display`) VALUES (289, '保存图片', '/api/admin/paper/picture/save', 'URL', 280, 1, 'AUTH', NULL, 1, 1, 1);
 
+
+-- 2024-08-05
+INSERT INTO `sys_privilege`(`id`, `name`, `url`, `type`, `parent_id`, `sequence`, `property`, `related`, `enable`, `default_auth`, `front_display`) VALUES (253, '单个考生数据清除接口', '/api/admin/paper/scan_task/clear_single_data', 'URL', 244, 4, 'AUTH', NULL, 1, 0, 1);
+update sys_privilege set related='251,253' where id=248;
+
+
 -- pdf图片生成-异步权限没加