diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java index f8ebc2f..31c9735 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java @@ -144,88 +144,18 @@ public class LeaveManage { if (po.getAttachments() != null) { leave.setAttachment(CollUtils.joinByComma(po.getAttachments())); } - LocalDateTime now = LocalDateTime.now(); leave.setType(po.getType()); leave.setRemark(po.getPostscript()); leave.setLeaveUserId(leaveUserId); leave.setCreator(LoginUserUtil.getUsername()); List> leaveDetailTimes = new ArrayList<>(); if (type.equals(LeaveTypeEnum.FIXED_TERM) || type.equals(LeaveTypeEnum.LONG_TERM)) { - boolean fixedTerm = CollUtil.isNotEmpty(po.getFixedType()); - if (fixedTerm) { - // 固定时段请假 - leave.setFixedType(CollUtils.joinByComma(po.getFixedType())); - } - LocalDateTime tempStart = po.getStartTime(); - while (!tempStart.isAfter(po.getEndTime())) { - boolean add = true; - if (fixedTerm) { - int weekday = tempStart.getDayOfWeek().getValue(); - add = po.getFixedType().contains(weekday); - } - if (add) { - LocalDateTime tempEnd = tempStart.toLocalDate().atTime(DateUtil.LOCAL_TIME_3D); - leaveDetailTimes.add(KeyValDTO.of(tempStart, DateUtil.min(tempEnd, po.getEndTime()))); - } - tempStart = tempStart.plusDays(1).toLocalDate().atStartOfDay(); - } - if (leaveDetailTimes.isEmpty()) { - throw BizException.wrap("请假时间无效"); - } - if (leaveDetailService.existsLeaveByUserIdAndTime(leaveUserId, leaveDetailTimes)) { - throw BizException.wrap("该请假时段内已存在请假"); - } - List meetingExperts = listMeetingExpert(leaveUserId, leaveDetailTimes); - if (!meetingExperts.isEmpty()) { - if (meetingExperts.stream().anyMatch(w -> ExpertAttendStatusEnum.AGREED.eq(w.getStatus()))) { - throw BizException.wrap("有待参加会议,请先处理完会议,再发起请假"); - } - List expertsUpdate = meetingExperts.stream() - .map(w -> buildMeetingExpertUpdate(w.getExpertId(), ExpertAttendStatusEnum.ON_LEAVE)) - .collect(Collectors.toList()); - meetingExpertService.updateBatchById(expertsUpdate); - } - leave.setStatus(LeaveStatusEnum.APPLYING.getCode()); - } else if (type.equals(LeaveTypeEnum.TEMPORARY)) { - // 临时请假 - Meeting meeting = meetingService.getById(po.getMeetingId()); - if (MeetingStatusEnum.CANCELED.eq(meeting.getStatus())) { - throw BizException.wrap("该会议已取消"); - } - po.setStartTime(meeting.getStartTime()); - po.setEndTime(meeting.getEndTime()); - if (now.plusHours(HOURS_BEFORE_MEETING).isAfter(po.getStartTime())) { - throw BizException.wrap("会议开始前" + HOURS_BEFORE_MEETING + "小时,不能在线请假,请电话该会议的联系人。"); - } - MeetingExpert expert = meetingExpertService.getByMeetingIdAndExpertId(po.getMeetingId(), leaveUserId); - if (!ExpertAttendStatusEnum.AGREED.eq(expert.getStatus())) { - // 非确认参加状态无法临时请假 - throw BizException.wrap("未同意参加该会议,无法临时请假"); - } - LocalDateTime tempStart = po.getStartTime(); - while (!tempStart.isAfter(po.getEndTime())) { - LocalDateTime tempEnd = tempStart.toLocalDate().atTime(DateUtil.LOCAL_TIME_3D); - leaveDetailTimes.add(KeyValDTO.of(tempStart, DateUtil.min(tempEnd, po.getEndTime()))); - tempStart = tempStart.plusDays(1).toLocalDate().atStartOfDay(); - } - LeaveManage proxy = (LeaveManage) AopContext.currentProxy(); - proxy.cancelMeetingExpertByLeave(expert.getId(), ExpertAttendStatusEnum.ON_LEAVE); - if (ExpertInviteTypeEnum.RANDOM.eq(meeting.getInviteType())) { - inviteTask.notifyInviteTask(meeting.getId(), Boolean.FALSE); - } - if (meeting.getConfirmedRoster()) { - LambdaUpdateWrapper mUpdate = Wrappers.lambdaUpdate(Meeting.class) - .set(Meeting::getConfirmedRoster, Boolean.FALSE) - .eq(Meeting::getId, meeting.getId()); - meetingService.update(mUpdate); - } - meetingCallOrMsgHelper.sendExpertLeaveMsg(expert, meeting); - // 临时请假无需审核 - leave.setAuditId(0L); - leave.setStatus(LeaveStatusEnum.PASSED.getCode()); + leaveProcessByDateRange(po, leaveUserId, leave, leaveDetailTimes); + } else if (LeaveTypeEnum.TEMPORARY.equals(type)) { + leaveProcessByTemporary(po, leaveUserId, leave, leaveDetailTimes); } if (type != LeaveTypeEnum.TEMPORARY) { - ExpertMetaApply apply = getExpertMetaApply(po, leaveUserId, applyUserId, now); + ExpertMetaApply apply = getExpertMetaApply(po, leaveUserId, applyUserId); leave.setAuditId(apply.getId()); if (!leaveForSelf) { leave.setStatus(LeaveStatusEnum.PASSED.getCode()); @@ -240,8 +170,86 @@ public class LeaveManage { return IdVo.of(leave.getId()); } - private ExpertMetaApply getExpertMetaApply(LeaveCreateReq po, Long leaveUserId, Long applyUserId, LocalDateTime now) { + private void leaveProcessByTemporary(LeaveCreateReq po, Long leaveUserId, ExpertLeave leave, List> leaveDetailTimes) { + // 临时请假 + Meeting meeting = meetingService.getById(po.getMeetingId()); + if (MeetingStatusEnum.CANCELED.eq(meeting.getStatus())) { + throw BizException.wrap("该会议已取消"); + } + po.setStartTime(meeting.getStartTime()); + po.setEndTime(meeting.getEndTime()); + if (LocalDateTime.now().plusHours(HOURS_BEFORE_MEETING).isAfter(po.getStartTime())) { + throw BizException.wrap("会议开始前" + HOURS_BEFORE_MEETING + "小时,不能在线请假,请电话该会议的联系人。"); + } + MeetingExpert expert = meetingExpertService.getByMeetingIdAndExpertId(po.getMeetingId(), leaveUserId); + if (!ExpertAttendStatusEnum.AGREED.eq(expert.getStatus())) { + // 非确认参加状态无法临时请假 + throw BizException.wrap("未同意参加该会议,无法临时请假"); + } + LocalDateTime tempStart = po.getStartTime(); + while (!tempStart.isAfter(po.getEndTime())) { + LocalDateTime tempEnd = tempStart.toLocalDate().atTime(DateUtil.LOCAL_TIME_3D); + leaveDetailTimes.add(KeyValDTO.of(tempStart, DateUtil.min(tempEnd, po.getEndTime()))); + tempStart = tempStart.plusDays(1).toLocalDate().atStartOfDay(); + } + LeaveManage proxy = (LeaveManage) AopContext.currentProxy(); + proxy.cancelMeetingExpertByLeave(expert.getId(), ExpertAttendStatusEnum.ON_LEAVE); + if (ExpertInviteTypeEnum.RANDOM.eq(meeting.getInviteType())) { + inviteTask.notifyInviteTask(meeting.getId(), Boolean.FALSE); + } + if (meeting.getConfirmedRoster()) { + LambdaUpdateWrapper mUpdate = Wrappers.lambdaUpdate(Meeting.class) + .set(Meeting::getConfirmedRoster, Boolean.FALSE) + .eq(Meeting::getId, meeting.getId()); + meetingService.update(mUpdate); + } + meetingCallOrMsgHelper.sendExpertLeaveMsg(expert, meeting); + // 临时请假无需审核 + leave.setAuditId(0L); + leave.setStatus(LeaveStatusEnum.PASSED.getCode()); + } + + private void leaveProcessByDateRange(LeaveCreateReq req, Long leaveUserId, ExpertLeave leave, List> leaveDetailTimes) { + boolean fixedTerm = CollUtil.isNotEmpty(req.getFixedType()); + if (fixedTerm) { + // 固定时段请假 + leave.setFixedType(CollUtils.joinByComma(req.getFixedType())); + } + LocalDateTime tempStart = req.getStartTime(); + while (!tempStart.isAfter(req.getEndTime())) { + boolean add = true; + if (fixedTerm) { + int weekday = tempStart.getDayOfWeek().getValue(); + add = req.getFixedType().contains(weekday); + } + if (add) { + LocalDateTime tempEnd = tempStart.toLocalDate().atTime(DateUtil.LOCAL_TIME_3D); + leaveDetailTimes.add(KeyValDTO.of(tempStart, DateUtil.min(tempEnd, req.getEndTime()))); + } + tempStart = tempStart.plusDays(1).toLocalDate().atStartOfDay(); + } + if (leaveDetailTimes.isEmpty()) { + throw BizException.wrap("请假时间无效"); + } + if (leaveDetailService.existsLeaveByUserIdAndTime(leaveUserId, leaveDetailTimes)) { + throw BizException.wrap("该请假时段内已存在请假"); + } + List meetingExperts = listMeetingExpert(leaveUserId, leaveDetailTimes); + if (!meetingExperts.isEmpty()) { + if (meetingExperts.stream().anyMatch(w -> ExpertAttendStatusEnum.AGREED.eq(w.getStatus()))) { + throw BizException.wrap("有待参加会议,请先处理完会议,再发起请假"); + } + List expertsUpdate = meetingExperts.stream() + .map(w -> buildMeetingExpertUpdate(w.getExpertId(), ExpertAttendStatusEnum.ON_LEAVE)) + .collect(Collectors.toList()); + meetingExpertService.updateBatchById(expertsUpdate); + } + leave.setStatus(LeaveStatusEnum.APPLYING.getCode()); + } + + private ExpertMetaApply getExpertMetaApply(LeaveCreateReq po, Long leaveUserId, Long applyUserId) { // 非临时请假需要审批 + LocalDateTime now = LocalDateTime.now(); ExpertMetaApply apply = new ExpertMetaApply(); apply.setCreateOn(now); apply.setUpdateOn(now);