|
@@ -868,10 +868,10 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void autoLayout(Long teachingId) {
|
|
|
- ApplyTaskEntity applyTask = getApplyTask();
|
|
|
- String autoLayoutLockKey = String.format(CacheConstants.LOCK_ARRANGE_EXAM,
|
|
|
- DateUtil.formatShortDateString(new Date()));
|
|
|
+ CurrentApplyTaskVO applyTask = cacheService.currentApplyTask(null);
|
|
|
+ String autoLayoutLockKey = String.format(CacheConstants.LOCK_ARRANGE_EXAM, DateUtil.formatShortDateString(new Date()));
|
|
|
RLock autoLayoutLock = (RLock) concurrentService.getLock(autoLayoutLockKey);
|
|
|
+
|
|
|
try {
|
|
|
if (!autoLayoutLock.tryLock()) {
|
|
|
log.warn("获取锁失败,已有线程在执行排考!lockKey:{}", autoLayoutLock);
|
|
@@ -881,34 +881,38 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
log.warn("获取锁成功!lockKey:{}", autoLayoutLockKey);
|
|
|
|
|
|
// 1.根据当前日期,查询不能取消的时段
|
|
|
- List<TimePeriodEntity> timePeriodList = listTimePeriod(applyTask.getId());
|
|
|
- List<TimePeriodEntity> noCancelTimePeroidList = listNoCancelApplyTimePeriod(timePeriodList,
|
|
|
- applyTask.getAllowApplyCancelDays());
|
|
|
+ List<TimePeriodEntity> timePeriodList = listTimePeriod(applyTask.getTaskId());
|
|
|
+ List<TimePeriodEntity> noCancelTimePeroidList = listNoCancelApplyTimePeriod(timePeriodList, applyTask.getAllowApplyCancelDays());
|
|
|
if (noCancelTimePeroidList.isEmpty()) {
|
|
|
- log.warn("当前时间不在取消预约范围内");
|
|
|
+ log.warn("[autoLayout] 没有待排考的时段");
|
|
|
return;
|
|
|
}
|
|
|
- // 2.查询考试日期的待排考的考生
|
|
|
- List<StudentApplyEntity> toBeLayoutStudentList = this.baseMapper.listTimePeriod(
|
|
|
- noCancelTimePeroidList.stream().map(BaseEntity::getId).collect(Collectors.toList()),
|
|
|
- Boolean.FALSE);
|
|
|
- if (toBeLayoutStudentList == null || toBeLayoutStudentList.isEmpty()) {
|
|
|
- log.warn("没有待排考的考生");
|
|
|
+
|
|
|
+ // 2.查询待排考的考生
|
|
|
+ List<Long> timePeriodIds = noCancelTimePeroidList.stream()
|
|
|
+ .map(BaseEntity::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<StudentApplyEntity> toBeLayoutStudentList = baseMapper.listTimePeriod(timePeriodIds, Boolean.FALSE);
|
|
|
+ if (CollectionUtils.isEmpty(toBeLayoutStudentList)) {
|
|
|
+ log.warn("[autoLayout] 没有待排考的考生");
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
// 3.开始排考
|
|
|
Map<Long, List<StudentApplyEntity>> toBeLayoutStudentMap = toBeLayoutStudentList.stream()
|
|
|
.collect(Collectors.groupingBy(StudentApplyEntity::getExamSiteId));
|
|
|
for (Long examSiteId : toBeLayoutStudentMap.keySet()) {
|
|
|
- Map<Long, List<StudentApplyEntity>> timeLayoutStudentMap = toBeLayoutStudentMap.get(examSiteId).stream()
|
|
|
+ List<StudentApplyEntity> studentApplyList= toBeLayoutStudentMap.get(examSiteId);
|
|
|
+ Map<Long, List<StudentApplyEntity>> timeLayoutStudentMap = studentApplyList.stream()
|
|
|
.collect(Collectors.groupingBy(StudentApplyEntity::getTimePeriodId));
|
|
|
+
|
|
|
List<ExamRoomEntity> roomList = listExamRoom(examSiteId);
|
|
|
if (roomList.isEmpty()) {
|
|
|
log.warn("{}:未设置考场", examSiteId);
|
|
|
return;
|
|
|
}
|
|
|
ExamSiteEntity examSite = examSiteService.getById(examSiteId);
|
|
|
- layoutStudentByTimePeriod(applyTask.getId(), examSite, roomList, timeLayoutStudentMap);
|
|
|
+ layoutStudentByTimePeriod(applyTask.getTaskId(), examSite, roomList, timeLayoutStudentMap);
|
|
|
}
|
|
|
} catch (StatusException e) {
|
|
|
log.error(e.getMessage());
|
|
@@ -929,7 +933,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
Map<Long, List<StudentApplyEntity>> timeLayoutStudentMap) {
|
|
|
for (Long timePeriodId : timeLayoutStudentMap.keySet()) {
|
|
|
List<StudentApplyEntity> studentApplyList = timeLayoutStudentMap.get(timePeriodId);
|
|
|
- layoutStudentToRoom(taskId, examSite, roomList, studentApplyList, timePeriodService.getById(timePeriodId));
|
|
|
+ TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodId);
|
|
|
+ layoutStudentToRoom(taskId, examSite, roomList, studentApplyList, timePeriod);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -940,23 +945,22 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
int num = 0;
|
|
|
for (Iterator<StudentApplyEntity> iterator = studentApplyList.iterator(); iterator.hasNext(); ) {
|
|
|
StudentApplyEntity student = iterator.next();
|
|
|
- if (num >= room.getCapacity())
|
|
|
+ if (num >= room.getCapacity()) {
|
|
|
break;
|
|
|
+ }
|
|
|
+ //座位号
|
|
|
String seatNumber = StringUtils.leftPad(String.valueOf(++num), 3, '0');
|
|
|
student.setExamRoomId(room.getId());
|
|
|
student.setSeatNumber(seatNumber);
|
|
|
- student.setTicketNumber(
|
|
|
- generateTicketNumber(timePeriodOrder, examSite.getCode(), room.getCode(), seatNumber));
|
|
|
- this.baseMapper.updateById(student);
|
|
|
+ // 准考证号
|
|
|
+ String ticketNum = DateUtil.formatShortDateString(new Date()) + timePeriodOrder + examSite.getCode() + room.getCode() + seatNumber;
|
|
|
+ student.setTicketNumber(ticketNum);
|
|
|
+ baseMapper.updateById(student);
|
|
|
iterator.remove();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private String generateTicketNumber(Integer timePeriodOrder, String examSiteCode, String roomCode,
|
|
|
- String seatNumber) {
|
|
|
- return DateUtil.formatShortDateString(new Date()) + timePeriodOrder + examSiteCode + roomCode + seatNumber;
|
|
|
- }
|
|
|
|
|
|
private Integer getTimePeriodOrder(Long taskId, TimePeriodEntity timePeriod) {
|
|
|
List<TimePeriodEntity> timeList = listTimePeriod(taskId);
|
|
@@ -969,20 +973,19 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- private List<TimePeriodEntity> listNoCancelApplyTimePeriod(List<TimePeriodEntity> list,
|
|
|
- Integer allowApplyCancelDays) {
|
|
|
- Date noCancelDate = getNoCancelApplyDate(allowApplyCancelDays);
|
|
|
- List<TimePeriodEntity> noCancelTimePeroidList = new ArrayList<>();
|
|
|
- for (TimePeriodEntity time : list) {
|
|
|
+ private List<TimePeriodEntity> listNoCancelApplyTimePeriod(List<TimePeriodEntity> list, Integer allowApplyCancelDays) {
|
|
|
+ // 不能修改预约的日期
|
|
|
+ Date noCancelDate = DateUtil.addValues(Calendar.DAY_OF_MONTH, allowApplyCancelDays);
|
|
|
+ return list.stream()
|
|
|
+ .filter( item -> isSameDay(noCancelDate, new Date(item.getStartTime())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ /*
|
|
|
+ List<TimePeriodEntity> noCancelTimePeroidList;
|
|
|
+ for (TimePeriodEntity time : list) {
|
|
|
+ // 预约的时段 和 不能修改预约的日期
|
|
|
if (isSameDay(noCancelDate, new Date(time.getStartTime())))
|
|
|
noCancelTimePeroidList.add(time);
|
|
|
- }
|
|
|
- return noCancelTimePeroidList;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private Date getNoCancelApplyDate(Integer allowApplyCancelDays) {
|
|
|
- return DateUtil.addValues(Calendar.DAY_OF_MONTH, allowApplyCancelDays);
|
|
|
+ }*/
|
|
|
}
|
|
|
|
|
|
@Override
|