Browse Source

专家请假方法提取

master
WendyYang 1 year ago
parent
commit
b2811313d2
1 changed files with 83 additions and 75 deletions
  1. +83
    -75
      pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java

+ 83
- 75
pmapi/src/main/java/com/ningdatech/pmapi/leave/manage/LeaveManage.java View File

@@ -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<KeyValDTO<LocalDateTime, LocalDateTime>> 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<MeetingExpert> meetingExperts = listMeetingExpert(leaveUserId, leaveDetailTimes);
if (!meetingExperts.isEmpty()) {
if (meetingExperts.stream().anyMatch(w -> ExpertAttendStatusEnum.AGREED.eq(w.getStatus()))) {
throw BizException.wrap("有待参加会议,请先处理完会议,再发起请假");
}
List<MeetingExpert> 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<Meeting> 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<KeyValDTO<LocalDateTime, LocalDateTime>> 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<Meeting> 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<KeyValDTO<LocalDateTime, LocalDateTime>> 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<MeetingExpert> meetingExperts = listMeetingExpert(leaveUserId, leaveDetailTimes);
if (!meetingExperts.isEmpty()) {
if (meetingExperts.stream().anyMatch(w -> ExpertAttendStatusEnum.AGREED.eq(w.getStatus()))) {
throw BizException.wrap("有待参加会议,请先处理完会议,再发起请假");
}
List<MeetingExpert> 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);


Loading…
Cancel
Save