|
@@ -12,10 +12,13 @@ import com.qmth.boot.tools.excel.enums.ExcelType;
|
|
|
import com.qmth.boot.tools.excel.model.DataMap;
|
|
|
import com.qmth.boot.tools.io.ZipWriter;
|
|
|
import com.qmth.exam.reserve.bean.Constants;
|
|
|
+import com.qmth.exam.reserve.bean.apply.ApplyRecordCacheBean;
|
|
|
import com.qmth.exam.reserve.bean.applytask.CurrentApplyTaskVO;
|
|
|
import com.qmth.exam.reserve.bean.category.CategoryCacheBean;
|
|
|
+import com.qmth.exam.reserve.bean.examsite.ExamSiteCacheBean;
|
|
|
import com.qmth.exam.reserve.bean.login.LoginUser;
|
|
|
import com.qmth.exam.reserve.bean.stdapply.*;
|
|
|
+import com.qmth.exam.reserve.bean.timeperiod.TimePeriodExamSiteBean;
|
|
|
import com.qmth.exam.reserve.cache.CacheConstants;
|
|
|
import com.qmth.exam.reserve.cache.impl.ApplyTaskCacheService;
|
|
|
import com.qmth.exam.reserve.cache.impl.CategoryCacheService;
|
|
@@ -54,9 +57,7 @@ import java.util.stream.Collectors;
|
|
|
import static org.apache.commons.lang3.time.DateUtils.isSameDay;
|
|
|
|
|
|
/**
|
|
|
- * @Description
|
|
|
- * @Author haoguanghui
|
|
|
- * @date 2024/06/24
|
|
|
+ * @Description 管理端-预约
|
|
|
*/
|
|
|
@Service
|
|
|
public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, StudentApplyEntity> implements StudentApplyService {
|
|
@@ -66,6 +67,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
private static final String[] EXCEL_HEADER = new String[]{"学号", "姓名", "证件号", "所属教学点", "预约考点1", "预约时段1", "预约考点2", "预约时段2", "预约考点3",
|
|
|
"预约时段3", "预约考点4", "预约时段4"};
|
|
|
|
|
|
+ private static final int maxApplyNum = 4;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ApplyTaskService applyTaskService;
|
|
|
|
|
@@ -185,11 +188,25 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
log.warn("[cancel] 获取锁失败,同一个考生不允许同时操作取消预约, lockKey:{}", studentApplyLockKey);
|
|
|
throw new StatusException(Constants.SYSTEM_BUSY);
|
|
|
} else {
|
|
|
- //先更新数据库
|
|
|
+
|
|
|
+ /* //先更新数据库
|
|
|
studentApplyEntity.setCancel(Boolean.TRUE);
|
|
|
updateById(studentApplyEntity);
|
|
|
+ */
|
|
|
+
|
|
|
+ ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
|
|
|
+ bean.setStudentId(studentApplyEntity.getStudentId());
|
|
|
+ bean.setExamSiteId(studentApplyEntity.getExamSiteId());
|
|
|
+ bean.setTimePeriodId(studentApplyEntity.getTimePeriodId());
|
|
|
+ bean.setCancel(Boolean.TRUE);
|
|
|
+ bean.setOperateId(user.getId());
|
|
|
+ bean.setOperateTime(System.currentTimeMillis());
|
|
|
|
|
|
- //扣减redis中的数量
|
|
|
+ // 先推送至预约队列
|
|
|
+ cacheService.pushStudentApplyRecordQueue(bean);
|
|
|
+ cacheService.saveStudentApplyRecord(bean);
|
|
|
+
|
|
|
+ // 扣减redis中的数量
|
|
|
cacheService.decreaseApplyFinishCount(studentApplyEntity.getExamSiteId(), studentApplyEntity.getTimePeriodId());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -227,20 +244,21 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
if (CollectionUtils.isEmpty(lineList)) {
|
|
|
throw new StatusException("Excel中没有任何考生预约数据");
|
|
|
}
|
|
|
- //TODO 结果:如果这里加全局锁,执行后考生和其他教学点将无法再次执行;如果不加锁,这里影响大不大,待讨论
|
|
|
+
|
|
|
+ List<Map<String, Object>> failRecords = new ArrayList<>();
|
|
|
RLock lock = (RLock) concurrentService.getLock(CacheConstants.LOCK_AUTO_APPLY);
|
|
|
- List<Map<String, Object>> failRecords;
|
|
|
+
|
|
|
try {
|
|
|
if (!lock.tryLock()) {
|
|
|
- log.warn("[importPreExam] 其他老师正在导入预考,获取锁失败!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
|
|
|
+ log.warn("[importPreExam] 其他教学点正在执行预约,获取锁失败!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
|
|
|
throw new StatusException("系统繁忙,请稍后重试!");
|
|
|
}
|
|
|
log.warn("[importPreExam] 获取锁成功!lockKey:{}", CacheConstants.LOCK_AUTO_APPLY);
|
|
|
|
|
|
- ApplyTaskEntity task = getApplyTask();
|
|
|
+ CurrentApplyTaskVO task = applyTaskCacheService.currentApplyTask(user.getOrgId());
|
|
|
Date openStartTime = new Date(task.getOpenApplyStartTime());
|
|
|
+ Date openEndTime = new Date(task.getOpenApplyEndTime());
|
|
|
Date now = new Date();
|
|
|
- failRecords = new ArrayList<>();
|
|
|
List<StudentImportVO> applyList = new ArrayList<>();
|
|
|
//教学点缓存
|
|
|
Map<String, Long> teachingCache = getTeachingCache(level);
|
|
@@ -248,8 +266,11 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
Map<String, Long> agentCache = getAgentCache();
|
|
|
//考试时段缓存
|
|
|
Map<String, TimePeriodEntity> timePeriodCache = getTimePeriodCache();
|
|
|
+ //考点时段缓存
|
|
|
+ Map<Long, Map<String, TimePeriodEntity>> timePeriodExamSiteCache = getTimePeriodExamSiteCache(task.getTaskId());
|
|
|
//考点所属教学点缓存
|
|
|
Map<Long, Long> examSiteCategoryCache = getExamSiteCategoryCache();
|
|
|
+
|
|
|
for (int i = 0; i < lineList.size(); i++) {
|
|
|
DataMap line = lineList.get(i);
|
|
|
List<AgentAndTimeVO> agentTimeList = new ArrayList<>();
|
|
@@ -273,7 +294,7 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
}
|
|
|
|
|
|
//判断考生是否存在
|
|
|
- StudentEntity studentEntity = checkStudent(studentCode, name, identityNumber, task);
|
|
|
+ StudentEntity studentEntity = checkStudent(studentCode, name, identityNumber, task.getTaskId());
|
|
|
if (studentEntity == null) {
|
|
|
msg.append(" 考生信息填写错误");
|
|
|
failRecords.add(newError(i + 1, msg.toString()));
|
|
@@ -300,38 +321,50 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
msg.append(" 非本教学点考生");
|
|
|
}
|
|
|
|
|
|
- String agentName1 = trimAndNullIfBlank(line.get(EXCEL_HEADER[4]));
|
|
|
- if (StringUtils.isBlank(agentName1)) {
|
|
|
+ String examSiteName = trimAndNullIfBlank(line.get(EXCEL_HEADER[4]));
|
|
|
+ if (StringUtils.isBlank(examSiteName)) {
|
|
|
msg.append(" 预约考点1不能为空");
|
|
|
}
|
|
|
- Long applyCategoryId;
|
|
|
- Long agentId = agentCache.get(agentName1);
|
|
|
- if (agentId == null) {
|
|
|
+ //考点所属教学点
|
|
|
+ Long applyTeachingId;
|
|
|
+ Long examSiteId = agentCache.get(examSiteName);
|
|
|
+ if (examSiteId == null) {
|
|
|
msg.append(" 预约考点1不存在");
|
|
|
} else {
|
|
|
- applyCategoryId = examSiteCategoryCache.get(agentId);
|
|
|
- if (now.before(openStartTime) && !categoryId.equals(applyCategoryId)) {
|
|
|
+ applyTeachingId = examSiteCategoryCache.get(examSiteId);
|
|
|
+ if ((now.before(openStartTime) || now.after(openEndTime)) && !categoryId.equals(applyTeachingId)) {
|
|
|
msg.append(" 未到自由预约时间,不能预约其他教学点下的考点");
|
|
|
}
|
|
|
+ //教学点管理员导入-不能预约其他教学点下的考点
|
|
|
+ if (now.after(openStartTime) && now.before(openEndTime) && user.getRole().equals(Role.TEACHING) && !categoryId.equals(applyTeachingId)) {
|
|
|
+ msg.append(" 不能预约其他教学点下的考点");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- String timePeriod1 = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
|
|
|
- if (StringUtils.isBlank(timePeriod1)) {
|
|
|
+ //预约的时段
|
|
|
+ String timePeriodStr = trimAndNullIfBlank(line.get(EXCEL_HEADER[5]));
|
|
|
+ if (StringUtils.isBlank(timePeriodStr)) {
|
|
|
msg.append(" 预约时段1不能为空");
|
|
|
}
|
|
|
- TimePeriodEntity timePeriod;
|
|
|
+ TimePeriodEntity timePeriodEntity;
|
|
|
+ Map<String, TimePeriodEntity> examSiteTimePeriodMap;
|
|
|
try {
|
|
|
- timePeriod = checkTimePeriod(timePeriod1, timePeriodCache);
|
|
|
- agentTime.setAgentId(agentId);
|
|
|
- agentTime.setTimePeriodId(timePeriod.getId());
|
|
|
- agentTime.setStartTime(timePeriod.getStartTime());
|
|
|
+ //考点下的预约时段
|
|
|
+ examSiteTimePeriodMap = timePeriodExamSiteCache.get(examSiteId);
|
|
|
+ if (examSiteTimePeriodMap != null) {
|
|
|
+ timePeriodCache = examSiteTimePeriodMap;
|
|
|
+ }
|
|
|
+ timePeriodEntity = checkTimePeriod(timePeriodStr, timePeriodCache);
|
|
|
+ agentTime.setAgentId(examSiteId);
|
|
|
+ agentTime.setTimePeriodId(timePeriodEntity.getId());
|
|
|
+ agentTime.setStartTime(timePeriodEntity.getStartTime());
|
|
|
agentTimeList.add(agentTime);
|
|
|
} catch (StatusException e) {
|
|
|
msg.append(" ").append(e.getMessage());
|
|
|
}
|
|
|
|
|
|
int index = 0;
|
|
|
- for (int num = 1; num <= 3; num++) {
|
|
|
+ for (int num = 1; num <= maxApplyNum; num++) {
|
|
|
String agentName = trimAndNullIfBlank(line.get(EXCEL_HEADER[num + 5 + index]));
|
|
|
String timePeriodName = trimAndNullIfBlank(line.get(EXCEL_HEADER[num + 6 + index]));
|
|
|
if (StringUtils.isBlank(agentName) && StringUtils.isBlank(timePeriodName)) {
|
|
@@ -341,21 +374,31 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
failRecords.add(newError(i + 1, msg.toString()));
|
|
|
break;
|
|
|
} else {
|
|
|
- agentId = agentCache.get(agentName);
|
|
|
- if (agentId == null) {
|
|
|
+ examSiteId = agentCache.get(agentName);
|
|
|
+ if (examSiteId == null) {
|
|
|
msg.append(" 预约考点").append(num + 1).append("不存在");
|
|
|
} else {
|
|
|
- applyCategoryId = examSiteCategoryCache.get(agentId);
|
|
|
- if (now.before(openStartTime) && !applyCategoryId.equals(categoryId)) {
|
|
|
+ applyTeachingId = examSiteCategoryCache.get(examSiteId);
|
|
|
+ if ((now.before(openStartTime) || now.after(openEndTime)) && !applyTeachingId.equals(categoryId)) {
|
|
|
msg.append(" 未到自由预约时间,不允许预约其他教学点的考点");
|
|
|
}
|
|
|
+ //教学点管理员导入-不能预约其他教学点下的考点
|
|
|
+ if (now.after(openStartTime) && now.before(openEndTime) && user.getRole().equals(Role.TEACHING) && !categoryId.equals(
|
|
|
+ applyTeachingId)) {
|
|
|
+ msg.append(" 不能预约其他教学点下的考点");
|
|
|
+ }
|
|
|
}
|
|
|
try {
|
|
|
- timePeriod = checkTimePeriod(timePeriodName, timePeriodCache);
|
|
|
+ //考点下的预约时段
|
|
|
+ examSiteTimePeriodMap = timePeriodExamSiteCache.get(examSiteId);
|
|
|
+ if (examSiteTimePeriodMap != null) {
|
|
|
+ timePeriodCache = examSiteTimePeriodMap;
|
|
|
+ }
|
|
|
+ timePeriodEntity = checkTimePeriod(timePeriodName, timePeriodCache);
|
|
|
agentTime = new AgentAndTimeVO();
|
|
|
- agentTime.setAgentId(agentId);
|
|
|
- agentTime.setTimePeriodId(timePeriod.getId());
|
|
|
- agentTime.setStartTime(timePeriod.getStartTime());
|
|
|
+ agentTime.setAgentId(examSiteId);
|
|
|
+ agentTime.setTimePeriodId(timePeriodEntity.getId());
|
|
|
+ agentTime.setStartTime(timePeriodEntity.getStartTime());
|
|
|
agentTimeList.add(agentTime);
|
|
|
} catch (StatusException e) {
|
|
|
msg.append(" ").append(e.getMessage());
|
|
@@ -364,11 +407,13 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
|
|
|
++index;
|
|
|
}
|
|
|
+
|
|
|
+ //检测考生是否已经完成预约和超出预约的最大次数
|
|
|
+ checkStudentTimePeriod(apply, i, task.getAllowApplyCancelDays(), failRecords);
|
|
|
}
|
|
|
- //检查导入excel的考生时段
|
|
|
- checkStudentApplyTime(applyList, task.getAllowApplyCancelDays(), failRecords);
|
|
|
- //过滤考生的可用时段
|
|
|
- filterAvailableTimePeriod(applyList, failRecords);
|
|
|
+
|
|
|
+ //考点容量判断
|
|
|
+ checkExamSiteTimeCapacity(applyList, failRecords);
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(failRecords)) {
|
|
|
return failRecords;
|
|
@@ -402,6 +447,42 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
return failRecords;
|
|
|
}
|
|
|
|
|
|
+ private Map<Long, Map<String, TimePeriodEntity>> getTimePeriodExamSiteCache(Long taskId) {
|
|
|
+ Map<Long, Map<String, TimePeriodEntity>> timePeriodExamSiteCache = new HashMap<>();
|
|
|
+ List<TimePeriodExamSiteBean> timePeriodExamSiteBeans = timePeriodService.listTimePeriodByExamSiteId(taskId, null);
|
|
|
+
|
|
|
+ // 过滤开启的预约时段
|
|
|
+ timePeriodExamSiteBeans = timePeriodExamSiteBeans.stream()
|
|
|
+ .filter(TimePeriodExamSiteBean::getEnable)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 按照考点分组
|
|
|
+ Map<Long, List<TimePeriodExamSiteBean>> timePeriodMap = timePeriodExamSiteBeans.stream()
|
|
|
+ .collect(Collectors.groupingBy(TimePeriodExamSiteBean::getExamSiteId));
|
|
|
+
|
|
|
+ Set<Map.Entry<Long, List<TimePeriodExamSiteBean>>> entries = timePeriodMap.entrySet();
|
|
|
+ for (Map.Entry<Long, List<TimePeriodExamSiteBean>> entry : entries) {
|
|
|
+ Long examSiteId = entry.getKey();
|
|
|
+ List<TimePeriodExamSiteBean> timePeriodExamSiteBeansList = entry.getValue();
|
|
|
+ // 时段转换为Map key: start_time + end_time
|
|
|
+ Map<String, TimePeriodEntity> map = getStringTimePeriodEntityMap(timePeriodExamSiteBeansList);
|
|
|
+
|
|
|
+ timePeriodExamSiteCache.put(examSiteId, map);
|
|
|
+ }
|
|
|
+ return timePeriodExamSiteCache;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, TimePeriodEntity> getStringTimePeriodEntityMap(List<TimePeriodExamSiteBean> timePeriodExamSiteBeansList) {
|
|
|
+ Map<String, TimePeriodEntity> map = new HashMap<>(timePeriodExamSiteBeansList.size());
|
|
|
+ for (TimePeriodExamSiteBean bean : timePeriodExamSiteBeansList) {
|
|
|
+ TimePeriodEntity entity = new TimePeriodEntity();
|
|
|
+ entity.setId(bean.getTimePeriodId());
|
|
|
+ entity.setStartTime(bean.getStartTime());
|
|
|
+ map.put(bean.getStartTime() + "-" + bean.getEndTime(), entity);
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
private void saveStudentApply(StudentImportVO vo, Long userId) {
|
|
|
List<AgentAndTimeVO> agentTimeList = vo.getAgentTimeList();
|
|
|
String studentApplyLockKey = String.format(CacheConstants.LOCK_STUDENT_APPLY, vo.getStudentId());
|
|
@@ -412,6 +493,8 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
} else {
|
|
|
log.warn("[importPreExam] 获取锁成功,lockKey:{}", studentApplyLockKey);
|
|
|
for (AgentAndTimeVO agentTimeVO : agentTimeList) {
|
|
|
+ /*
|
|
|
+ //数据库操作
|
|
|
StudentApplyEntity studentApply = new StudentApplyEntity();
|
|
|
studentApply.setStudentId(vo.getStudentId());
|
|
|
studentApply.setExamSiteId(agentTimeVO.getAgentId());
|
|
@@ -424,8 +507,21 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
baseMapper.updateById(existStudentApply);
|
|
|
} else {
|
|
|
baseMapper.insert(studentApply);
|
|
|
- }
|
|
|
- //redis的数量加1
|
|
|
+ }*/
|
|
|
+
|
|
|
+ // 队列bean组装
|
|
|
+ ApplyRecordCacheBean bean = new ApplyRecordCacheBean();
|
|
|
+ bean.setStudentId(vo.getStudentId());
|
|
|
+ bean.setExamSiteId(agentTimeVO.getAgentId());
|
|
|
+ bean.setTimePeriodId(agentTimeVO.getTimePeriodId());
|
|
|
+ bean.setCancel(Boolean.FALSE);
|
|
|
+ bean.setOperateId(userId);
|
|
|
+ bean.setOperateTime(System.currentTimeMillis());
|
|
|
+
|
|
|
+ // 先推送至预约队列
|
|
|
+ cacheService.pushStudentApplyRecordQueue(bean);
|
|
|
+ cacheService.saveStudentApplyRecord(bean);
|
|
|
+ // redis已预约数量+1
|
|
|
cacheService.increaseApplyFinishCount(agentTimeVO.getAgentId(), agentTimeVO.getTimePeriodId());
|
|
|
}
|
|
|
}
|
|
@@ -453,63 +549,80 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
return baseMapper.selectOne(wrapper);
|
|
|
}
|
|
|
|
|
|
- private void filterAvailableTimePeriod(List<StudentImportVO> applyList, List<Map<String, Object>> failRecords) {
|
|
|
- int index = 0;
|
|
|
- for (StudentImportVO apply : applyList) {
|
|
|
- index++;
|
|
|
- List<AgentAndTimeVO> agentTimeList = apply.getAgentTimeList();
|
|
|
- List<StudentApplyEntity> haveApplyList = listStudentHaveApply(apply.getStudentId());
|
|
|
- int studentApplyFinishCount = haveApplyList.size();
|
|
|
- agentTimeList.sort(Comparator.comparing(AgentAndTimeVO::getStartTime));
|
|
|
+ private void checkStudentTimePeriod(StudentImportVO studentImportVO, int row, int allowCancelDays, List<Map<String, Object>> failRecords) {
|
|
|
+ List<AgentAndTimeVO> agentTimeList = studentImportVO.getAgentTimeList();
|
|
|
+
|
|
|
+ //是否重复预约时段
|
|
|
+ boolean isDuplicate = agentTimeList.stream()
|
|
|
+ .collect(Collectors.groupingBy(AgentAndTimeVO::getTimePeriodId, Collectors.counting()))
|
|
|
+ .entrySet()
|
|
|
+ .stream()
|
|
|
+ .anyMatch(entry -> entry.getValue() > 1);
|
|
|
+ if (isDuplicate) {
|
|
|
+ failRecords.add(newError(row + 1, "同一个考生预约的时间不能相同"));
|
|
|
+ }
|
|
|
+ //预约的日期,是否在可取消日期之后
|
|
|
+ LocalDate day = LocalDate.now().plusDays(allowCancelDays);
|
|
|
+ long epochMilli = day.plusDays(1).atStartOfDay(ZoneId.systemDefault()).minusSeconds(1).toInstant().toEpochMilli();
|
|
|
+ for (AgentAndTimeVO time : agentTimeList) {
|
|
|
+ if (time.getStartTime() <= epochMilli) {
|
|
|
+ failRecords.add(newError(row + 1, "预约的考试时段,只能为" + allowCancelDays + "天之后的时段"));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- List<AgentAndTimeVO> toBeApplyTimeList = new ArrayList<>();
|
|
|
+ /* 数据库的方式
|
|
|
+ List<StudentApplyEntity> haveApplyList = listStudentHaveApply(studentImportVO.getStudentId());
|
|
|
+ int studentApplyFinishCount = haveApplyList.size();*/
|
|
|
|
|
|
- //考生已完成预约
|
|
|
- if (studentApplyFinishCount >= apply.getApplyNumber()) {
|
|
|
- apply.setAgentTimeList(toBeApplyTimeList);
|
|
|
- failRecords.add(newError(index, "请先取消考生已预约的信息"));
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // 考生已经预约的次数
|
|
|
+ int studentApplyFinishCount = applyTaskCacheService.getStudentApplyFinishCount(studentImportVO.getStudentId());
|
|
|
+ List<AgentAndTimeVO> toBeApplyTimeList = new ArrayList<>();
|
|
|
|
|
|
- //考生未完成预约
|
|
|
- List<AgentAndTimeVO> availableList = listAvailableTime(haveApplyList, agentTimeList);
|
|
|
- toBeApplyTimeList.addAll(availableList);
|
|
|
+ //考生已完成预约
|
|
|
+ if (studentApplyFinishCount >= studentImportVO.getApplyNumber()) {
|
|
|
+ studentImportVO.setAgentTimeList(toBeApplyTimeList);
|
|
|
+ failRecords.add(newError(row + 1, "考生已完成预约,请先取消考生已预约的信息"));
|
|
|
+ }
|
|
|
|
|
|
- //判断是否超过可预约次数
|
|
|
- if (apply.getApplyNumber() < haveApplyList.size() + availableList.size()) {
|
|
|
- failRecords.add(newError(index, "超过考生可预约的最大数量:" + apply.getApplyNumber()));
|
|
|
- } else {
|
|
|
- apply.setAgentTimeList(toBeApplyTimeList);
|
|
|
- }
|
|
|
+ //判断是否超过可预约次数
|
|
|
+ if (studentImportVO.getApplyNumber() < studentApplyFinishCount + agentTimeList.size()) {
|
|
|
+ failRecords.add(newError(row + 1, "超过考生可预约的最大数量:" + studentImportVO.getApplyNumber()));
|
|
|
}
|
|
|
- //是否超过-考点的容量
|
|
|
- checkExamSiteTimeCapacity(applyList, failRecords);
|
|
|
}
|
|
|
|
|
|
private void checkExamSiteTimeCapacity(List<StudentImportVO> applyList, List<Map<String, Object>> failRecords) {
|
|
|
try {
|
|
|
+ //导入的所有时段
|
|
|
List<AgentAndTimeVO> availableTimeList = new ArrayList<>();
|
|
|
applyList.forEach(item -> availableTimeList.addAll(item.getAgentTimeList()));
|
|
|
+
|
|
|
+ //按照考点+时段 分组
|
|
|
Map<Long, Map<Long, List<AgentAndTimeVO>>> agentTimeMap = availableTimeList.stream()
|
|
|
.collect(Collectors.groupingBy(AgentAndTimeVO::getAgentId, Collectors.groupingBy(AgentAndTimeVO::getTimePeriodId)));
|
|
|
+
|
|
|
for (Map.Entry<Long, Map<Long, List<AgentAndTimeVO>>> examSiteEntry : agentTimeMap.entrySet()) {
|
|
|
Long examSiteId = examSiteEntry.getKey();
|
|
|
Map<Long, List<AgentAndTimeVO>> timePeriodMap = examSiteEntry.getValue();
|
|
|
- //考点的容量
|
|
|
- int examSiteCapacity = cacheService.getApplyTotalCount(examSiteId);
|
|
|
for (Map.Entry<Long, List<AgentAndTimeVO>> timePeriodEntry : timePeriodMap.entrySet()) {
|
|
|
Long timePeriodKey = timePeriodEntry.getKey();
|
|
|
- //考点下某个时段已预约的容量
|
|
|
- int examSiteTimeCapacity = cacheService.getApplyFinishCount(examSiteId, timePeriodKey);
|
|
|
+
|
|
|
+ //考点下某个时段可预约的容量
|
|
|
+ int availableCount = cacheService.getApplyAvailableCount(examSiteId, timePeriodKey);
|
|
|
// 导入的某个考点,某个时段的数量
|
|
|
int impTimePeriodNum = timePeriodEntry.getValue().size();
|
|
|
- if (examSiteCapacity < impTimePeriodNum + examSiteTimeCapacity) {
|
|
|
- String examSiteName = examSiteCacheService.getExamSiteById(examSiteId).getExamSiteName();
|
|
|
- TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodKey);
|
|
|
- String startAndEndTime = DateUtil.getStartAndEndTime(timePeriod.getStartTime(), timePeriod.getEndTime());
|
|
|
- log.warn("[importPreExam],{} {} 剩余容量为:{},而导入的数量为:{}", examSiteName, startAndEndTime, examSiteCapacity - examSiteTimeCapacity, impTimePeriodNum);
|
|
|
- failRecords.add(newError(0,
|
|
|
- examSiteName + " " + startAndEndTime + " 剩余容量为:" + (examSiteCapacity - examSiteTimeCapacity) + ",而导入的数量为:" + impTimePeriodNum));
|
|
|
+
|
|
|
+ if (impTimePeriodNum > availableCount) {
|
|
|
+ ExamSiteCacheBean examSiteBean = examSiteCacheService.getExamSiteById(examSiteId);
|
|
|
+ if (examSiteBean != null) {
|
|
|
+ String examSiteName = examSiteBean.getExamSiteName();
|
|
|
+ TimePeriodEntity timePeriod = timePeriodService.getById(timePeriodKey);
|
|
|
+ String startAndEndTime = DateUtil.getStartAndEndTime(timePeriod.getStartTime(), timePeriod.getEndTime());
|
|
|
+
|
|
|
+ log.warn("[importPreExam],{} {} 剩余容量为:{},而导入的数量为:{}", examSiteName, startAndEndTime, availableCount, impTimePeriodNum);
|
|
|
+ failRecords.add(newError(0,
|
|
|
+ examSiteName + " " + startAndEndTime + " 剩余容量为:" + (availableCount) + ",而导入的数量为:" + impTimePeriodNum));
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -568,11 +681,11 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private TimePeriodEntity checkTimePeriod(String timePeriod, Map<String, TimePeriodEntity> timeCache) {
|
|
|
- if (timePeriod == null || timePeriod.split(" ").length != 2) {
|
|
|
+ private TimePeriodEntity checkTimePeriod(String timePeriodStr, Map<String, TimePeriodEntity> timeCache) {
|
|
|
+ if (timePeriodStr == null || timePeriodStr.split(" ").length != 2) {
|
|
|
throw new StatusException(" 预约时段格式不正确");
|
|
|
}
|
|
|
- String[] arr = timePeriod.split("-");
|
|
|
+ String[] arr = timePeriodStr.split("-");
|
|
|
String startTime = arr[0] + ":00";
|
|
|
String endTime = startTime.substring(0, startTime.indexOf("日") + 1) + " " + arr[1] + ":00";
|
|
|
Long startTimeLong = DateUtil.getLongTimeByZHDate(startTime);
|
|
@@ -590,12 +703,12 @@ public class StudentApplyServiceImpl extends ServiceImpl<StudentApplyDao, Studen
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- private StudentEntity checkStudent(String studentCode, String studentName, String identityNumber, ApplyTaskEntity task) {
|
|
|
+ private StudentEntity checkStudent(String studentCode, String studentName, String identityNumber, Long taskId) {
|
|
|
LambdaQueryWrapper<StudentEntity> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StudentEntity::getStudentCode, studentCode);
|
|
|
wrapper.eq(StudentEntity::getName, studentName);
|
|
|
wrapper.eq(StudentEntity::getIdentityNumber, identityNumber);
|
|
|
- wrapper.eq(StudentEntity::getApplyTaskId, task.getId());
|
|
|
+ wrapper.eq(StudentEntity::getApplyTaskId, taskId);
|
|
|
return studentService.getOne(wrapper);
|
|
|
}
|
|
|
|