haogh 1 жил өмнө
parent
commit
6f2df56b48

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

@@ -17,6 +17,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
 
+import com.qmth.exam.reserve.entity.base.BaseEntity;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.time.DateUtils;
 import org.redisson.api.RLock;
@@ -387,19 +388,18 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     }
 
     private void checkAvailableTimePeriod(List<StudentImportVO> applyList) {
-        for (int i = 0; i < applyList.size(); i++) {
-            StudentImportVO vo = applyList.get(i);
+        for (StudentImportVO vo : applyList) {
             List<AgentAndTimeVO> agentTimeList = vo.getAgentTimeList();
             List<StudentApplyEntity> haveApplyList = listStudentApply(vo.getStudentId(), Boolean.FALSE);
             int studentApplyFinishCount = cacheService.getStudentApplyFinishCount(vo.getStudentId());
             if (studentApplyFinishCount == 0) {
                 studentApplyFinishCount = haveApplyList.size();
             }
-            Collections.sort(agentTimeList, Comparator.comparing(AgentAndTimeVO::getStartTime));
+            agentTimeList.sort(Comparator.comparing(AgentAndTimeVO::getStartTime));
             List<AgentAndTimeVO> tobeInsertTimeList = new ArrayList<>();
 
             // 考生已经完成预约-不做处理
-            if (studentApplyFinishCount >= vo.getApplyNumber().intValue()) {
+            if (studentApplyFinishCount >= vo.getApplyNumber()) {
                 vo.setAgentTimeList(tobeInsertTimeList);
                 continue;
             }
@@ -427,6 +427,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             for (StudentApplyEntity apply : haveApplyList) {
                 if (time.getTimePeriodId().equals(apply.getTimePeriodId())) {
                     flag = true;
+                    break;
                 }
             }
             if (!flag) {
@@ -450,7 +451,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             if (isDuplicate) {
                 failRecords.add(newError(i + 1, " 预约的时间不能相同"));
             }
-            LocalDate day = LocalDate.now().plusDays(days.intValue());
+            LocalDate day = LocalDate.now().plusDays(days);
             long epochMilli = day.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusSeconds(1).toInstant()
                     .toEpochMilli();
             for (AgentAndTimeVO time : agentTimeList) {
@@ -634,7 +635,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                     for (TimePeriodEntity time : timeList) {
                         // 该时段已预约的考生
                         Integer haveApplyNum = cacheService.getApplyFinishCount(site.getId(), time.getId());
-                        if (haveApplyNum == null || haveApplyNum == 0) {
+                        if (haveApplyNum == 0) {
                             haveApplyNum = getHaveApplyNum(site.getId(), time.getId());
                         }
                         // 剩余的考位
@@ -644,7 +645,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                     }
                 }
                 // 4、判断是否还有剩余考生未完成预约,提醒考位不够
-                if (teachingStudentList.size() > 0)
+                if (!teachingStudentList.isEmpty())
                     throw new StatusException("【" + categoryService.getById(key).getName() + "】教学点考位不足");
             }
         } catch (Exception e) {
@@ -766,7 +767,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
         wrapper.eq(StudentApplyEntity::getStudentId, studentId);
         wrapper.eq(StudentApplyEntity::getCancel, Boolean.FALSE);
         StudentApplyEntity studentApply = baseMapper.selectOne(wrapper);
-        return studentApply == null ? false : true;
+        return studentApply != null;
     }
 
     private Integer getHaveApplyNum(Long siteId, Long timeId) {
@@ -813,11 +814,11 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     }
 
     private Integer getNoApplyNum(List<StudentEntity> list) {
-        Integer noApplyNum = 0;
+        int noApplyNum = 0;
         for (StudentEntity student : list) {
-            if (student.getApplyNumber().intValue() == 1) {
+            if (student.getApplyNumber() == 1) {
                 noApplyNum++;
-            } else if (student.getApplyNumber().intValue() > 1) {
+            } else if (student.getApplyNumber() > 1) {
                 // listStudentApply(student.getId(), Boolean.FALSE).size()
                 int haveApplyNum = cacheService.getStudentApplyFinishCount(student.getId());
                 noApplyNum = noApplyNum + (student.getApplyNumber() - haveApplyNum);
@@ -856,10 +857,6 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
     @Override
     public void autoLayout(Long teachingId) {
         ApplyTaskEntity applyTask = getApplyTask();
-        if (applyTask == null) {
-            log.info("没有开启预约任务");
-            return;
-        }
         String autoLayoutLockKey = String.format(CacheConstants.LOCK_ARRANGE_EXAM,
                 DateUtil.formatShortDateString(new Date()));
         RLock autoLayoutLock = (RLock) concurrentService.getLock(autoLayoutLockKey);
@@ -929,7 +926,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             List<StudentApplyEntity> studentApplyList, TimePeriodEntity timePeriod) {
         Integer timePeriodOrder = getTimePeriodOrder(taskId, timePeriod);
         for (ExamRoomEntity room : roomList) {
-            Integer num = 0;
+            int num = 0;
             for (Iterator<StudentApplyEntity> iterator = studentApplyList.iterator(); iterator.hasNext();) {
                 StudentApplyEntity student = iterator.next();
                 if (num >= room.getCapacity())
@@ -1096,7 +1093,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
             signInList.add(vo);
         }
 
-        for (int i = 1; i <= task.getAllowApplyCancelDays().intValue(); i++) {
+        for (int i = 1; i <= task.getAllowApplyCancelDays(); i++) {
             Date otherDay = DateUtil.addValues(today, Calendar.DAY_OF_MONTH, i);
             Long longOtherDay = DateUtil.getLongTimeByDate(DateUtil.formatShortSplitDateString(otherDay) + " 00:00:00");
             if (longOtherDay >= startTime && longOtherDay <= endTime) {
@@ -1105,7 +1102,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
                 signInList.add(vo);
             }
         }
-        Collections.sort(signInList, Comparator.comparing(SignInVO::getExamDate));
+        signInList.sort(Comparator.comparing(SignInVO::getExamDate));
         return signInList;
     }