浏览代码

code optimize

haogh 1 年之前
父节点
当前提交
85c005ecf6

+ 2 - 1
src/main/java/com/qmth/exam/reserve/service/impl/FileUploadServiceImpl.java

@@ -3,6 +3,7 @@ package com.qmth.exam.reserve.service.impl;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.nio.file.Files;
 import java.time.Duration;
 
 import org.slf4j.Logger;
@@ -28,7 +29,7 @@ public class FileUploadServiceImpl implements FileUploadService {
         try {
             OssStore store = new OssStore(property.getServer(), property.getConfig());
             String filePath = dirName + "/" + file.getName();
-            store.write(filePath, new FileInputStream(file), ByteArray.md5(file).toHexString());
+            store.write(filePath, Files.newInputStream(file.toPath()), ByteArray.md5(file).toHexString());
             String url = store.getPresignedUrl(filePath, Duration.ofMinutes(5));
             store.close();
             return url;

+ 25 - 25
src/main/java/com/qmth/exam/reserve/service/impl/StudentApplyServiceImpl.java

@@ -194,7 +194,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     @Override
     public List<Map<String, Object>> importPreExam(Long userId, Long teachingId, Integer level,
             InputStream inputStream) {
-        List<DataMap> lineList = null;
+        List<DataMap> lineList;
         ExcelReader reader = ExcelReader.create(ExcelType.XLSX, inputStream, 0);
         try {
             lineList = reader.getDataMapList();
@@ -214,9 +214,9 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         Map<String, Long> teachingCache = getTeachingCache(level);
         Map<String, Long> agentCache = getAgentCache();
         Map<String, TimePeriodEntity> timeCache = getTimePeriodCache();
-        Map<Long, Long> examSiteCategroyCache = getExamSiteCategroyCache();
+        Map<Long, Long> examSiteCategoryCache = getExamSiteCategoryCache();
         List<StudentImportVO> applyList = new ArrayList<>();
-        AgentAndTimeVO agentTime = new AgentAndTimeVO();
+        AgentAndTimeVO agentTime;
         for (int i = 0; i < lineList.size(); i++) {
             List<AgentAndTimeVO> agentTimeList = new ArrayList<>();
             DataMap line = lineList.get(i);
@@ -268,7 +268,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             if (agentId == null) {
                 msg.append(" 预约考点1不存在");
             } else {
-                applyCategoryId = examSiteCategroyCache.get(agentId);
+                applyCategoryId = examSiteCategoryCache.get(agentId);
                 if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
                     msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
                 }
@@ -302,7 +302,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 if (agentId == null) {
                     msg.append(" 预约考点2不存在");
                 } else {
-                    applyCategoryId = examSiteCategroyCache.get(agentId);
+                    applyCategoryId = examSiteCategoryCache.get(agentId);
                     if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
                         msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
                     }
@@ -332,7 +332,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 if (agentId == null) {
                     msg.append(" 预约考点3不存在");
                 } else {
-                    applyCategoryId = examSiteCategroyCache.get(agentId);
+                    applyCategoryId = examSiteCategoryCache.get(agentId);
                     if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
                         msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
                     }
@@ -362,7 +362,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 if (agentId == null) {
                     msg.append(" 预约考点4不存在");
                 } else {
-                    applyCategoryId = examSiteCategroyCache.get(agentId);
+                    applyCategoryId = examSiteCategoryCache.get(agentId);
                     if (now.before(openStartTime) && categoryId != null && !applyCategoryId.equals(categoryId)) {
                         msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
                     }
@@ -408,12 +408,12 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
 
     }
 
-    private Map<Long, Long> getExamSiteCategroyCache() {
+    private Map<Long, Long> getExamSiteCategoryCache() {
         Map<Long, Long> cache = new HashMap<>();
         LambdaQueryWrapper<ExamSiteEntity> lm = new LambdaQueryWrapper<>();
         lm.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
         List<ExamSiteEntity> examSiteList = examSiteService.list(lm);
-        examSiteList.stream().forEach(site -> {
+        examSiteList.forEach(site -> {
             cache.put(site.getId(), site.getCategoryId());
         });
         return cache;
@@ -655,7 +655,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             Map<Long, List<StudentEntity>> noFinishApplyMap = studentList.stream()
                     .collect(Collectors.groupingBy(StudentEntity::getCategoryId));
             // 2、考位是否充足
-            List<TimePeriodEntity> timeList = listTimePeroid(taskId);
+            List<TimePeriodEntity> timeList = listTimePeriod(taskId);
             timeList = listNoCancelExamTimePeriod(timeList, taskId);
             checkTeachingCapacity(noFinishApplyMap, timeList, taskId);
             // 3、按照教学点安排考位。规则:不能和已预约的时间上有冲突
@@ -764,7 +764,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                     }
                 }
             } catch (Exception e) {
-                log.error("自动安排预约失败,错误信息:" + e.getMessage());
+                log.error("自动安排预约失败,错误信息:{}", e.getMessage());
                 throw new StatusException("自动安排预约失败,请稍后再试!");
             } finally {
                 try {
@@ -864,7 +864,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return this.baseMapper.selectList(lm);
     }
 
-    private List<TimePeriodEntity> listTimePeroid(Long taskId) {
+    private List<TimePeriodEntity> listTimePeriod(Long taskId) {
         LambdaQueryWrapper<TimePeriodEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(TimePeriodEntity::getApplyTaskId, taskId);
         wrapper.orderByAsc(TimePeriodEntity::getStartTime);
@@ -875,10 +875,10 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return timeList;
     }
 
-    private List<ExamSiteEntity> listExamSite(Long categoryId, Long examsiteId) {
+    private List<ExamSiteEntity> listExamSite(Long categoryId, Long examSiteId) {
         LambdaQueryWrapper<ExamSiteEntity> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(ExamSiteEntity::getCategoryId, categoryId);
-        wrapper.eq(examsiteId != null, ExamSiteEntity::getId, examsiteId);
+        wrapper.eq(examSiteId != null, ExamSiteEntity::getId, examSiteId);
         wrapper.eq(ExamSiteEntity::getEnable, Boolean.TRUE);
         return examSiteService.list(wrapper);
     }
@@ -899,8 +899,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             log.warn("获取锁成功!lockKey:{}", autoLayoutLockKey);
 
             // 1.根据当前日期,查询不能取消的时段
-            List<TimePeriodEntity> timePeriodList = listTimePeroid(applyTask.getId());
-            List<TimePeriodEntity> noCancelTimePeroidList = listNoCancelApplyTimePeroid(timePeriodList,
+            List<TimePeriodEntity> timePeriodList = listTimePeriod(applyTask.getId());
+            List<TimePeriodEntity> noCancelTimePeroidList = listNoCancelApplyTimePeriod(timePeriodList,
                     applyTask.getAllowApplyCancelDays());
             if (noCancelTimePeroidList.isEmpty()) {
                 log.warn("当前时间不在取消预约范围内");
@@ -922,7 +922,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                         .collect(Collectors.groupingBy(StudentApplyEntity::getTimePeriodId));
                 List<ExamRoomEntity> roomList = listExamRoom(examSiteId);
                 if (roomList.isEmpty()) {
-                    log.warn(examSiteId + ":未设置考场");
+                    log.warn("{}:未设置考场", examSiteId);
                     return;
                 }
                 ExamSiteEntity examSite = examSiteService.getById(examSiteId);
@@ -973,8 +973,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     }
 
     private Integer getTimePeriodOrder(Long taskId, TimePeriodEntity timePeriod) {
-        List<TimePeriodEntity> timeList = listTimePeroid(taskId);
-        List<TimePeriodEntity> sameDayTimeList = listSameDayTimePeroid(timeList, timePeriod.getStartTime());
+        List<TimePeriodEntity> timeList = listTimePeriod(taskId);
+        List<TimePeriodEntity> sameDayTimeList = listSameDayTimePeriod(timeList, timePeriod.getStartTime());
         for (int i = 0; i < sameDayTimeList.size(); i++) {
             TimePeriodEntity time = sameDayTimeList.get(i);
             if (time.getStartTime().equals(timePeriod.getStartTime()))
@@ -983,7 +983,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return 0;
     }
 
-    private List<TimePeriodEntity> listSameDayTimePeroid(List<TimePeriodEntity> timeList, Long startTime) {
+    private List<TimePeriodEntity> listSameDayTimePeriod(List<TimePeriodEntity> timeList, Long startTime) {
         Date day = new Date(startTime);
         List<TimePeriodEntity> resultList = new ArrayList<>();
         for (TimePeriodEntity time : timeList) {
@@ -1006,8 +1006,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         return examRoomService.list(wrapper);
     }
 
-    private List<TimePeriodEntity> listNoCancelApplyTimePeroid(List<TimePeriodEntity> list,
-            Integer allowApplyCancelDays) {
+    private List<TimePeriodEntity> listNoCancelApplyTimePeriod(List<TimePeriodEntity> list,
+                                                               Integer allowApplyCancelDays) {
         Date noCancelDate = getNoCancelApplyDate(allowApplyCancelDays);
         List<TimePeriodEntity> noCancelTimePeroidList = new ArrayList<>();
         for (TimePeriodEntity time : list) {
@@ -1025,8 +1025,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     @Override
     public File downloadSignIn(Long teachingId, Long agentId, Long examDate) {
         ApplyTaskEntity applyTask = getApplyTask();
-        List<TimePeriodEntity> timePeriodList = listTimePeroid(applyTask.getId());
-        List<TimePeriodEntity> noCancelTimePeroidList = listSameDayTimePeroid(timePeriodList, examDate);
+        List<TimePeriodEntity> timePeriodList = listTimePeriod(applyTask.getId());
+        List<TimePeriodEntity> noCancelTimePeroidList = listSameDayTimePeriod(timePeriodList, examDate);
         if (noCancelTimePeroidList.isEmpty()) {
             throw new StatusException("当前时间没有可下载的签到表");
         }
@@ -1106,7 +1106,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             return signInList;
         }
 
-        List<TimePeriodEntity> timePeriodList = listTimePeroid(task.getId());
+        List<TimePeriodEntity> timePeriodList = listTimePeriod(task.getId());
         if (timePeriodList.isEmpty()) {
             log.warn("未配置考试时段");
             return signInList;