|
@@ -41,6 +41,7 @@ import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert; |
|
|
import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertAttendStatusEnum; |
|
|
import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertAttendStatusEnum; |
|
|
import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertInviteTypeEnum; |
|
|
import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertInviteTypeEnum; |
|
|
import com.ningdatech.pmapi.meeting.entity.enumeration.MeetingStatusEnum; |
|
|
import com.ningdatech.pmapi.meeting.entity.enumeration.MeetingStatusEnum; |
|
|
|
|
|
import com.ningdatech.pmapi.meeting.helper.MeetingCallOrMsgHelper; |
|
|
import com.ningdatech.pmapi.meeting.service.IMeetingExpertService; |
|
|
import com.ningdatech.pmapi.meeting.service.IMeetingExpertService; |
|
|
import com.ningdatech.pmapi.meeting.service.IMeetingService; |
|
|
import com.ningdatech.pmapi.meeting.service.IMeetingService; |
|
|
import com.ningdatech.pmapi.meeting.task.ExpertRandomInviteTask; |
|
|
import com.ningdatech.pmapi.meeting.task.ExpertRandomInviteTask; |
|
@@ -77,6 +78,7 @@ public class LeaveManage { |
|
|
private final IExpertMetaApplyService metaApplyService; |
|
|
private final IExpertMetaApplyService metaApplyService; |
|
|
private final FileService fileService; |
|
|
private final FileService fileService; |
|
|
private final IExpertUserFullInfoService userFullInfoService; |
|
|
private final IExpertUserFullInfoService userFullInfoService; |
|
|
|
|
|
private final MeetingCallOrMsgHelper meetingCallOrMsgHelper; |
|
|
|
|
|
|
|
|
private static final int HOURS_BEFORE_MEETING = 2; |
|
|
private static final int HOURS_BEFORE_MEETING = 2; |
|
|
|
|
|
|
|
@@ -142,87 +144,18 @@ public class LeaveManage { |
|
|
if (po.getAttachments() != null) { |
|
|
if (po.getAttachments() != null) { |
|
|
leave.setAttachment(CollUtils.joinByComma(po.getAttachments())); |
|
|
leave.setAttachment(CollUtils.joinByComma(po.getAttachments())); |
|
|
} |
|
|
} |
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
|
leave.setType(po.getType()); |
|
|
leave.setType(po.getType()); |
|
|
leave.setRemark(po.getPostscript()); |
|
|
leave.setRemark(po.getPostscript()); |
|
|
leave.setLeaveUserId(leaveUserId); |
|
|
leave.setLeaveUserId(leaveUserId); |
|
|
leave.setCreator(LoginUserUtil.getUsername()); |
|
|
leave.setCreator(LoginUserUtil.getUsername()); |
|
|
List<KeyValDTO<LocalDateTime, LocalDateTime>> leaveDetailTimes = new ArrayList<>(); |
|
|
List<KeyValDTO<LocalDateTime, LocalDateTime>> leaveDetailTimes = new ArrayList<>(); |
|
|
if (type.equals(LeaveTypeEnum.FIXED_TERM) || type.equals(LeaveTypeEnum.LONG_TERM)) { |
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
// 临时请假无需审核 |
|
|
|
|
|
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) { |
|
|
if (type != LeaveTypeEnum.TEMPORARY) { |
|
|
ExpertMetaApply apply = getExpertMetaApply(po, leaveUserId, applyUserId, now); |
|
|
|
|
|
|
|
|
ExpertMetaApply apply = getExpertMetaApply(po, leaveUserId, applyUserId); |
|
|
leave.setAuditId(apply.getId()); |
|
|
leave.setAuditId(apply.getId()); |
|
|
if (!leaveForSelf) { |
|
|
if (!leaveForSelf) { |
|
|
leave.setStatus(LeaveStatusEnum.PASSED.getCode()); |
|
|
leave.setStatus(LeaveStatusEnum.PASSED.getCode()); |
|
@@ -237,8 +170,86 @@ public class LeaveManage { |
|
|
return IdVo.of(leave.getId()); |
|
|
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(); |
|
|
ExpertMetaApply apply = new ExpertMetaApply(); |
|
|
apply.setCreateOn(now); |
|
|
apply.setCreateOn(now); |
|
|
apply.setUpdateOn(now); |
|
|
apply.setUpdateOn(now); |
|
|