Jelajahi Sumber

联调修改

caozixuan 1 tahun lalu
induk
melakukan
e1cbbe07b6

+ 0 - 1
install/mysql/init/init.sql

@@ -88,7 +88,6 @@ CREATE TABLE `pm_exam_student`
     `sort_no`      bigint(20)                    NOT NULL,
     `name`         varchar(255) COLLATE utf8_bin DEFAULT NULL,
     `course_code`  varchar(255) COLLATE utf8_bin NOT NULL,
-    `course_name` varchar(255) COLLATE utf8_bin NOT NULL COMMENT '课程名称',
     `student_code` varchar(255) COLLATE utf8_bin DEFAULT NULL,
     `exam_number`  varchar(255) COLLATE utf8_bin NOT NULL,
     `exam_site`    varchar(255) COLLATE utf8_bin DEFAULT NULL,

+ 0 - 3
install/mysql/upgrade/1.1.0.sql

@@ -3,6 +3,3 @@ ALTER TABLE pm_user
 
 ALTER TABLE pm_exam_student
     ADD COLUMN exam_unit VARCHAR(255) NULL COMMENT '服务单元' AFTER exam_room;
-
-ALTER TABLE pm_exam_student
-    ADD COLUMN course_name VARCHAR(255) NOT NULL COMMENT '课程名称' AFTER course_code;

+ 2 - 0
src/main/java/cn/com/qmth/print/manage/config/PmConstants.java

@@ -14,6 +14,8 @@ public interface PmConstants {
 
     public static final String MD5 = "MD5";
 
+    public static final String LING_SIGN = "_";
+
     /**
      * 默认密码
      */

+ 24 - 0
src/main/java/cn/com/qmth/print/manage/config/SysProperty.java

@@ -0,0 +1,24 @@
+package cn.com.qmth.print.manage.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+/**
+ * @Description:
+ * @Author: CaoZixuan
+ * @Date:
+ */
+@Component
+public class SysProperty {
+
+    @Value("${temp-data-dir}")
+    private String tempDataDir;
+
+    public String getTempDataDir() {
+        return tempDataDir;
+    }
+
+    public void setTempDataDir(String tempDataDir) {
+        this.tempDataDir = tempDataDir;
+    }
+}

+ 2 - 1
src/main/java/cn/com/qmth/print/manage/controller/ConditionController.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.print.manage.controller;
 
+import cn.com.qmth.print.manage.config.PmConstants;
 import cn.com.qmth.print.manage.entity.ExamStudentEntity;
 import cn.com.qmth.print.manage.enums.GroupType;
 import cn.com.qmth.print.manage.enums.RecordStatus;
@@ -79,7 +80,7 @@ public class ConditionController {
         List<ExamStudentEntity> studentEntityList = examStudentService.listByExamId(examId);
         List<String> courseCodeList = new ArrayList<>();
         if (!CollectionUtils.isEmpty(studentEntityList)) {
-            courseCodeList = studentEntityList.stream().map(m -> m.getCourseCode()).distinct()
+            courseCodeList = studentEntityList.stream().map(ExamStudentEntity::getCourseCode).distinct()
                     .collect(Collectors.toList());
         }
         return courseCodeList;

+ 2 - 1
src/main/java/cn/com/qmth/print/manage/controller/ExamStudentController.java

@@ -11,6 +11,7 @@ import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.IOException;
@@ -23,7 +24,7 @@ import java.io.IOException;
 @Aac(strict = BOOL.FALSE, auth = BOOL.TRUE)
 public class ExamStudentController extends BaseController {
 
-    @Autowired
+    @Resource
     private ExamStudentService examStudentService;
 
     /**

+ 0 - 10
src/main/java/cn/com/qmth/print/manage/entity/ExamStudentEntity.java

@@ -18,8 +18,6 @@ public class ExamStudentEntity extends AuditingWithoutIdEntity {
 
     private String courseCode;
 
-    private String courseName;
-
     private String name;
 
     private String studentCode;
@@ -63,14 +61,6 @@ public class ExamStudentEntity extends AuditingWithoutIdEntity {
         this.courseCode = courseCode;
     }
 
-    public String getCourseName() {
-        return courseName;
-    }
-
-    public void setCourseName(String courseName) {
-        this.courseName = courseName;
-    }
-
     public String getName() {
         return name;
     }

+ 5 - 5
src/main/java/cn/com/qmth/print/manage/service/ExamService.java

@@ -24,17 +24,17 @@ public interface ExamService extends IService<ExamEntity> {
     /**
      * 导入考试
      *
-     * @param requestUser 请求用户
-     * @param printLeader 印点负责人
-     * @param file        文件
+     * @param requestUser   请求用户
+     * @param printLeaderId 印点负责人
+     * @param file          文件
      * @return 报错信息
      */
-    Object importExams(UserEntity requestUser, Long printLeader, MultipartFile file) throws IOException;
+    Object importExams(UserEntity requestUser, Long printLeaderId, MultipartFile file) throws IOException;
 
     /**
      * 删除考试批次
+     *
      * @param examId 考试id
      */
     void deleteExam(Long examId);
-
 }

+ 10 - 12
src/main/java/cn/com/qmth/print/manage/service/impl/BreakRecordServiceImpl.java

@@ -1,12 +1,5 @@
 package cn.com.qmth.print.manage.service.impl;
 
-import java.util.Date;
-import java.util.List;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
 import cn.com.qmth.print.manage.dao.BreakRecordDao;
 import cn.com.qmth.print.manage.entity.BreakRecordEntity;
 import cn.com.qmth.print.manage.entity.ExamEntity;
@@ -20,7 +13,6 @@ import cn.com.qmth.print.manage.service.ExamStudentService;
 import cn.com.qmth.print.manage.service.UserService;
 import cn.com.qmth.print.manage.service.query.RecordQuery;
 import cn.com.qmth.print.manage.vo.BreakRecordVo;
-
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
@@ -28,21 +20,27 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.exception.StatusException;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Date;
+import java.util.List;
 
 @Service
 public class BreakRecordServiceImpl extends ServiceImpl<BreakRecordDao, BreakRecordEntity> implements
         BreakRecordService {
 
-    @Autowired
+    @Resource
     private BreakRecordDao breakRecordDao;
 
-    @Autowired
+    @Resource
     private ExamStudentService studentService;
 
-    @Autowired
+    @Resource
     private ExamService examService;
 
-    @Autowired
+    @Resource
     private UserService userService;
 
     @Override

+ 6 - 5
src/main/java/cn/com/qmth/print/manage/service/impl/CheckRecordServiceImpl.java

@@ -1,5 +1,6 @@
 package cn.com.qmth.print.manage.service.impl;
 
+import cn.com.qmth.print.manage.config.PmConstants;
 import cn.com.qmth.print.manage.dao.CheckRecordDao;
 import cn.com.qmth.print.manage.entity.CheckRecordEntity;
 import cn.com.qmth.print.manage.entity.ExamEntity;
@@ -22,9 +23,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.boot.core.exception.StatusException;
 import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
 
@@ -32,16 +33,16 @@ import java.util.List;
 public class CheckRecordServiceImpl extends ServiceImpl<CheckRecordDao, CheckRecordEntity> implements
         CheckRecordService {
 
-    @Autowired
+    @Resource
     private CheckRecordDao checkRecordDao;
 
-    @Autowired
+    @Resource
     private ExamStudentService studentService;
 
-    @Autowired
+    @Resource
     private ExamService examService;
 
-    @Autowired
+    @Resource
     private UserService userService;
 
     @Override

+ 17 - 8
src/main/java/cn/com/qmth/print/manage/service/impl/ExamServiceImpl.java

@@ -106,8 +106,9 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
 
     @Override
     public IPage<ExamVo> pageQuery(ExamQuery query) {
-        Page<ExamVo> page = new Page<>(query.getPageNumber(), query.getPageSize());
-        IPage<ExamVo> iPage = this.baseMapper.pageExam(page, query);
+        // TODO: 2023/10/23 分页查询异常 
+//        Page<ExamVo> page = new Page<>(query.getPageNumber(), query.getPageSize());
+        IPage<ExamVo> iPage = this.baseMapper.pageExam(new Page<>(query.getPageNumber(), query.getPageSize()), query);
         for (ExamVo record : iPage.getRecords()) {
             // 考生总量
             List<ExamStudentEntity> studentEntityList = examStudentService.listByExamId(record.getId());
@@ -145,8 +146,12 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
             }
 
             // 计算进度
-            BigDecimal progress = new BigDecimal(record.getCheckNormalLCount()).divide(new BigDecimal(record.getCheckCount()), 4, RoundingMode.HALF_UP);
-            progress = progress.multiply(new BigDecimal(100));
+            BigDecimal progress = BigDecimal.ZERO;
+            int checkCount = record.getCheckCount();
+            if (checkCount > 0) {
+                progress = new BigDecimal(record.getCheckNormalLCount()).divide(new BigDecimal(record.getCheckCount()), 4, RoundingMode.HALF_UP);
+                progress = progress.multiply(new BigDecimal(100));
+            }
             record.setProgress(progress);
         }
         return iPage;
@@ -172,8 +177,12 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
                 vo.setCheckErrorCount(Math.toIntExact(checkErrorLCount));
 
                 // 计算进度
-                BigDecimal progress = new BigDecimal(vo.getCheckNormalLCount()).divide(new BigDecimal(vo.getCheckCount()), 4, RoundingMode.HALF_UP);
-                progress = progress.multiply(new BigDecimal(100));
+                BigDecimal progress = BigDecimal.ZERO;
+                int checkCount = vo.getCheckCount();
+                if (checkCount > 0){
+                    progress = new BigDecimal(vo.getCheckNormalLCount()).divide(new BigDecimal(checkCount), 4, RoundingMode.HALF_UP);
+                    progress = progress.multiply(new BigDecimal(100));
+                }
                 vo.setProgress(progress);
             }
             return Stream.of(vo);
@@ -181,7 +190,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
     }
 
     @Override
-    public List<ExcelError> importExams(UserEntity requestUser, Long printLeader, MultipartFile file) throws IOException {
+    public List<ExcelError> importExams(UserEntity requestUser, Long printLeaderId, MultipartFile file) throws IOException {
         List<String> examNameDatasource = this.list().stream()
                 .map(ExamEntity::getName)
                 .collect(Collectors.toList());
@@ -210,7 +219,7 @@ public class ExamServiceImpl extends ServiceImpl<ExamDao, ExamEntity> implements
                 examEntity.setCheckSort(CheckSort.ASC);
                 examEntity.setCreateTime(new Date());
                 examEntity.setUpdateTime(new Date());
-                examEntity.setCreatorId(requestUser.getCreatorId());
+                examEntity.setCreatorId(printLeaderId);
                 examEntityList.add(examEntity);
                 return null;
             } catch (RuntimeException e) {

+ 95 - 68
src/main/java/cn/com/qmth/print/manage/service/impl/ExamStudentServiceImpl.java

@@ -1,5 +1,7 @@
 package cn.com.qmth.print.manage.service.impl;
 
+import cn.com.qmth.print.manage.config.PmConstants;
+import cn.com.qmth.print.manage.config.SysProperty;
 import cn.com.qmth.print.manage.dao.ExamDao;
 import cn.com.qmth.print.manage.dao.ExamStudentDao;
 import cn.com.qmth.print.manage.dto.ExamStudentExportDTO;
@@ -54,21 +56,38 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
     @Resource
     private ExamDao examDao;
 
+    @Resource
+    private SysProperty sysProperty;
+
     @Override
     public ExamStudentEntity findByExamIdAndExamNumber(Long examId, String examNumber) {
-        // TODO: 2023/10/20 校验更改逻辑 
         if (examId == null) {
             throw new StatusException("examId不能为空");
         }
         if (StringUtils.isEmpty(examNumber)) {
             throw new StatusException("准考证号不能为空");
         }
-        QueryWrapper<ExamStudentEntity> wrapper = new QueryWrapper<>();
-        LambdaQueryWrapper<ExamStudentEntity> lw = wrapper.lambda();
-        lw.eq(ExamStudentEntity::getExamId, examId);
-        lw.eq(ExamStudentEntity::getExamNumber, examNumber);
-        ExamStudentEntity entity = this.getOne(wrapper);
-        return entity;
+        ExamStudentEntity result;
+        // 判断examNumber是否为大条码(学号)
+        ExamStudentEntity checkStudentCode = this.getOne(new QueryWrapper<ExamStudentEntity>()
+                .lambda()
+                .eq(ExamStudentEntity::getExamId, examId)
+                .eq(ExamStudentEntity::getStudentCode, examNumber));
+        if (Objects.nonNull(checkStudentCode)) {
+            result = checkStudentCode;
+        } else {
+            // 判断examNumber是否为小条码(去掉末尾和examNumber)
+            examNumber = examNumber.substring(0, examNumber.length() - 1);
+            ExamStudentEntity checkExamNumber = this.getOne(new QueryWrapper<ExamStudentEntity>()
+                    .lambda()
+                    .eq(ExamStudentEntity::getExamId, examId)
+                    .eq(ExamStudentEntity::getExamNumber, examNumber));
+            if (Objects.isNull(checkExamNumber)) {
+                throw new StatusException("未找到考生[" + examNumber + "]");
+            }
+            result = checkExamNumber;
+        }
+        return result;
     }
 
     @Override
@@ -167,75 +186,83 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
 
     @Transactional
     @Override
-    public Object analyzeZipAndImportStudents(Long examId ,MultipartFile file) throws IOException {
-        String zipPath = "E:\\file\\studentImport2.zip";
-        String dirPath = "E:\\file\\studentImport2";
-//        File zip = new File("E:\\file\\studentImport2.zip");
-//        File zipDir = new File("E:\\file\\studentImport2");
-        Zip4jUtil.unzipEncryptFile(zipPath,dirPath,"qmth!@#");
-//        File zip = new File("E:\\file\\studentImport2.zip");
-        File zipDir = new File("E:\\file\\studentImport2");
-        File[] firstDirArr = zipDir.listFiles();
-        if (Objects.isNull(firstDirArr) || firstDirArr.length != 1) {
-            throw new StatusException("文件解析失败:未找到一级目录");
-        }
-        List<File> studentFileList = Arrays.stream(Objects.requireNonNull(firstDirArr[0].listFiles()))
-                .filter(e -> e.getName().endsWith("xlsx"))
-                .collect(Collectors.toList());
-        if (CollectionUtils.isEmpty(studentFileList)) {
-            throw new StatusException("文件解析失败:未找到导入的excel文件");
-        }
-        if (studentFileList.size() != 1) {
-            throw new StatusException("文件解析失败:存在多个excel文件");
-        }
-        File studentExcel = studentFileList.get(0);
+    public Object analyzeZipAndImportStudents(Long examId, MultipartFile file) throws IOException {
+        String tempPath = sysProperty.getTempDataDir() + "/examStudent";
+        try {
+            File tempZipFile = new File(tempPath + "/examStudent.zip");
+            if (!tempZipFile.exists()) {
+                tempZipFile.mkdirs();
+            }
+            file.transferTo(tempZipFile);
+            String zipPath = tempZipFile.getPath();
+            String dirPath = tempPath + "/examStudent";
 
-        ExamEntity examEntity = examDao.selectById(examId);
-        List<ExamStudentEntity> studentList = new ArrayList<>();
-        ExcelReader excelReader = new ExcelReader(ExamStudentImportDTO.class);
-        AtomicLong sort = new AtomicLong(1L);
-        List<ExcelError> excelErrors = excelReader.reader(FileUtil.getInputStream(studentExcel), obj -> {
-            try {
-                ExamStudentImportDTO dto = (ExamStudentImportDTO) obj;
-                ExamStudentEntity examStudentEntity = new ExamStudentEntity();
-                examStudentEntity.setExamId(examId);
-                examStudentEntity.setOrgId(examEntity.getOrgId());
-                examStudentEntity.setExamNumber(dto.getExamNumber());
-                examStudentEntity.setStudentCode(dto.getStudentCode());
-                examStudentEntity.setName(dto.getStudentName());
-                examStudentEntity.setCourseCode(dto.getCourseCode());
-                examStudentEntity.setCourseName(dto.getCourseName());
-                examStudentEntity.setExamSite(dto.getExamPlaceName());
-                examStudentEntity.setSortNo(sort.getAndIncrement());
-                examStudentEntity.setExamUnit(dto.getExamUnit());
-                examStudentEntity.setCreateTime(new Date());
-                examStudentEntity.setUpdateTime(new Date());
-                studentList.add(examStudentEntity);
-                return null;
-            } catch (RuntimeException e) {
-                // 手动回滚
-                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
-                ExcelError excelError = new ExcelError();
-                excelError.setExcelErrorType(e.getMessage());
-                return excelError;
+            Zip4jUtil.unzipEncryptFile(zipPath, dirPath, "qmth!@#");
+
+            File zipDir = new File(dirPath);
+            File[] firstDirArr = zipDir.listFiles();
+            if (Objects.isNull(firstDirArr) || firstDirArr.length != 1) {
+                throw new StatusException("文件解析失败:未找到一级目录");
             }
-        });
+            List<File> studentFileList = Arrays.stream(Objects.requireNonNull(firstDirArr[0].listFiles()))
+                    .filter(e -> e.getName().endsWith("xlsx"))
+                    .collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(studentFileList)) {
+                throw new StatusException("文件解析失败:未找到导入的excel文件");
+            }
+            if (studentFileList.size() != 1) {
+                throw new StatusException("文件解析失败:存在多个excel文件");
+            }
+            File studentExcel = studentFileList.get(0);
 
-        String errors = errorsString(excelErrors);
-        if (errors.length() > 0) {
-            throw new StatusException(errors);
-        }
+            ExamEntity examEntity = examDao.selectById(examId);
+            List<ExamStudentEntity> studentList = new ArrayList<>();
+            ExcelReader excelReader = new ExcelReader(ExamStudentImportDTO.class);
+            AtomicLong sort = new AtomicLong(1L);
+            List<ExcelError> excelErrors = excelReader.reader(FileUtil.getInputStream(studentExcel), obj -> {
+                try {
+                    ExamStudentImportDTO dto = (ExamStudentImportDTO) obj;
+                    ExamStudentEntity examStudentEntity = new ExamStudentEntity();
+                    examStudentEntity.setExamId(examId);
+                    examStudentEntity.setOrgId(examEntity.getOrgId());
+                    examStudentEntity.setExamNumber(dto.getExamNumber());
+                    examStudentEntity.setStudentCode(dto.getStudentCode());
+                    examStudentEntity.setName(dto.getStudentName());
+                    examStudentEntity.setCourseCode(dto.getCourseCode() + PmConstants.LING_SIGN + dto.getCourseName());
+                    examStudentEntity.setExamSite(dto.getExamPlaceName());
+                    examStudentEntity.setSortNo(sort.getAndIncrement());
+                    examStudentEntity.setExamUnit(dto.getExamUnit());
+                    examStudentEntity.setCreateTime(new Date());
+                    examStudentEntity.setUpdateTime(new Date());
+                    studentList.add(examStudentEntity);
+                    return null;
+                } catch (RuntimeException e) {
+                    // 手动回滚
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    ExcelError excelError = new ExcelError();
+                    excelError.setExcelErrorType(e.getMessage());
+                    return excelError;
+                }
+            });
 
-        if (!CollectionUtils.isEmpty(studentList)) {
-            insertData(examEntity, studentList);
+            String errors = errorsString(excelErrors);
+            if (errors.length() > 0) {
+                throw new StatusException(errors);
+            }
+
+            if (!CollectionUtils.isEmpty(studentList)) {
+                insertData(examEntity, studentList);
+            }
+            return excelErrors;
+        } finally {
+            FileUtil.del(tempPath);
         }
-        return excelErrors;
     }
 
     @Override
     public void exportExamStudent(HttpServletResponse response, Long examId) throws IOException {
         List<ExamStudentExportDTO> examStudentExportDTOList = this.baseMapper.findExportData(examId);
-        new ExportExcel("考生数据", ExamStudentExportDTO.class).setDataList(examStudentExportDTOList).write(response, "")
+        new ExportExcel("考生数据", ExamStudentExportDTO.class).setDataList(examStudentExportDTOList).write(response, "考生数据.xlsx")
                 .dispose();
     }
 
@@ -250,8 +277,8 @@ public class ExamStudentServiceImpl extends ServiceImpl<ExamStudentDao, ExamStud
     public void insertData(ExamEntity examEntity, List<ExamStudentEntity> studentList) {
         // 有校验数据不能删除
         if (checkRecordService.count(new QueryWrapper<CheckRecordEntity>().lambda()
-                .eq(CheckRecordEntity::getExamId,examEntity.getId())
-                .ne(CheckRecordEntity::getStatus,RecordStatus.NONE)) > 0){
+                .eq(CheckRecordEntity::getExamId, examEntity.getId())
+                .ne(CheckRecordEntity::getStatus, RecordStatus.NONE)) > 0) {
             throw new StatusException("已有校验数据,不可重复导入");
         }
 

+ 1 - 1
src/main/java/cn/com/qmth/print/manage/service/impl/UserServiceImpl.java

@@ -80,7 +80,7 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
         boolean result = this.saveOrUpdate(user);
         if (RoleMeta.ADMIN.equals(requestUser.getRole()) && Objects.nonNull(file)) {
             // 如果是管理员且包含导入文件-处理导入批次逻辑
-            examService.importExams(requestUser, id, file);
+            examService.importExams(requestUser, user.getId(), file);
         }
         return result;
     }

+ 2 - 2
src/main/resources/mapper/ExamStudentDao.xml

@@ -4,8 +4,8 @@
 
     <select id="findExportData" resultType="cn.com.qmth.print.manage.dto.ExamStudentExportDTO">
         SELECT
-            course_code AS subjectCode,
-            course_name AS subjectName,
+            SUBSTRING_INDEX(course_code,'_',1) AS subjectCode,
+            SUBSTRING_INDEX(course_code,'_',2) AS subjectName,
             exam_number AS examNumber,
             student_code AS studentCode,
             name AS name,