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 64d0c2b..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 @@ -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.ExpertInviteTypeEnum; 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.IMeetingService; import com.ningdatech.pmapi.meeting.task.ExpertRandomInviteTask; @@ -77,6 +78,7 @@ public class LeaveManage { private final IExpertMetaApplyService metaApplyService; private final FileService fileService; private final IExpertUserFullInfoService userFullInfoService; + private final MeetingCallOrMsgHelper meetingCallOrMsgHelper; private static final int HOURS_BEFORE_MEETING = 2; @@ -142,87 +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); - } - // 临时请假无需审核 - 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()); @@ -237,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); diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/constant/MeetingMsgTemplateConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/constant/MeetingMsgTemplateConst.java index 90cf49a..3a865db 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/constant/MeetingMsgTemplateConst.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/constant/MeetingMsgTemplateConst.java @@ -25,4 +25,8 @@ public interface MeetingMsgTemplateConst { */ String MEETING_CANCEL = "尊敬的%s专家,原定于%s的%s会议已取消。给您带来不便,敬请谅解。如有疑问请咨询会议联系人「%s」。"; + String EXPERT_LEAVE_RANDOM = "请注意,%s会议有专家请假,将重新抽取以替换该专家。"; + + String EXPERT_LEAVE_APPOINT = "请注意,%s会议的%s专家请假,请及时登录系统替换该专家。"; + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingCallOrMsgHelper.java b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingCallOrMsgHelper.java index 0955e82..9de3586 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingCallOrMsgHelper.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/meeting/helper/MeetingCallOrMsgHelper.java @@ -7,6 +7,7 @@ import com.ningdatech.basic.util.CollUtils; import com.ningdatech.pmapi.meeting.constant.MeetingMsgTemplateConst; import com.ningdatech.pmapi.meeting.entity.domain.Meeting; import com.ningdatech.pmapi.meeting.entity.domain.MeetingExpert; +import com.ningdatech.pmapi.meeting.entity.enumeration.ExpertInviteTypeEnum; import com.ningdatech.pmapi.meeting.entity.enumeration.MeetingReviewTypeEnum; import com.ningdatech.pmapi.organization.model.entity.DingEmployeeInfo; import com.ningdatech.pmapi.organization.model.entity.DingOrganization; @@ -187,4 +188,29 @@ public class MeetingCallOrMsgHelper { experts.forEach(w -> w.setSubmitKey(submitKey)); } + public void sendExpertLeaveMsg(MeetingExpert expert, Meeting meeting) { + Long userId = meeting.getCreateBy(); + String msgContent; + if (ExpertInviteTypeEnum.RANDOM.eq(meeting.getInviteType())) { + msgContent = String.format(MeetingMsgTemplateConst.EXPERT_LEAVE_RANDOM, meeting.getName()); + } else { + msgContent = String.format(MeetingMsgTemplateConst.EXPERT_LEAVE_APPOINT, meeting.getName(), expert.getExpertName()); + } + UserInfo info = userInfoService.getById(userId); + SendSmsContext yxtContent = new SendSmsContext(); + yxtContent.setContent(msgContent); + yxtContent.setReceiveNumber(info.getMobile()); + yxtCallOrSmsHelper.sendSms(yxtContent); + // 发送工作通知 + if (info.getAccountId() != null) { + WorkNoticeInfo swn = getSendWorkNoticeInfo(info.getAccountId()); + swn.setMsg(msgContent); + workNoticeStagingService.addByWorkNotice(swn, MsgTypeEnum.REVIEW_MEETING); + Map map = new HashMap<>(2); + map.put("meetingId", meeting.getId()); + Notify notify = getNotify(userId, msgContent, MsgTypeEnum.REVIEW_MEETING, map); + notifyService.save(notify); + } + } + }