| | |
| | | package me.zhengjie.modules.conferenceRoom.service.impl; |
| | | |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.assetManagement.domain.AssetManagement; |
| | | import me.zhengjie.modules.assetManagement.domain.AssetUseManagement; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceGoOut; |
| | | import me.zhengjie.modules.conferenceRoom.domain.MeetingRoom; |
| | | import me.zhengjie.modules.conferenceRoom.domain.MeetingRoomReservation; |
| | | import me.zhengjie.modules.conferenceRoom.repository.MeetingRoomRepository; |
| | | import me.zhengjie.modules.conferenceRoom.service.dto.MeetingRoomDto; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.system.domain.CustomerResources; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import me.zhengjie.modules.system.domain.Role; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.conferenceRoom.repository.MeetingRoomReservationRepository; |
| | | import me.zhengjie.modules.conferenceRoom.service.MeetingRoomReservationService; |
| | | import me.zhengjie.modules.conferenceRoom.service.dto.MeetingRoomReservationDto; |
| | | import me.zhengjie.modules.conferenceRoom.service.dto.MeetingRoomReservationQueryCriteria; |
| | | import me.zhengjie.modules.conferenceRoom.service.mapstruct.MeetingRoomReservationMapper; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | import java.util.function.Function; |
| | | |
| | | /** |
| | | * @author wcd |
| | | * @website https://eladmin.vip |
| | | * @description 服务实现 |
| | | * @author wcd |
| | | * @date 2023-02-09 |
| | | **/ |
| | | @Service |
| | |
| | | private final MeetingRoomReservationRepository meetingRoomReservationRepository; |
| | | private final MeetingRoomReservationMapper meetingRoomReservationMapper; |
| | | private final MeetingRoomRepository meetingRoomRepository; |
| | | private final OpaiDingTalkService opaiDingTalkService; |
| | | private final WeComServiceImpl weComService; |
| | | private final UserRepository userRepository; |
| | | |
| | | @Override |
| | |
| | | throw new BadRequestException("预约时间冲突," + errorFormat.format(errorMeetingRoomReservation.getStartTime()) + "至" + errorFormat.format(errorMeetingRoomReservation.getEndTime()) |
| | | + "已经存在会议室预约,请调整时间"); |
| | | }else{ |
| | | //调用钉钉公共方法 |
| | | setDingding(resources); |
| | | // 发送通知 |
| | | sendNotice(resources); |
| | | } |
| | | return meetingRoomReservationMapper.toDto(meetingRoomReservationRepository.save(resources)); |
| | | } |
| | |
| | | throw new BadRequestException("预约时间冲突," + errorFormat.format(errorMeetingRoomReservation.getStartTime()) + "至" + errorFormat.format(errorMeetingRoomReservation.getEndTime()) |
| | | + "已经存在会议室预约,请调整时间"); |
| | | }else{ |
| | | setDingding(resources); |
| | | // 发送通知 |
| | | sendNotice(resources); |
| | | } |
| | | meetingRoomReservationRepository.save(meetingRoomReservation); |
| | | } |
| | | |
| | | /** |
| | | * 发送钉钉公共方法 |
| | | * 向其他应用发送通知公共方法 |
| | | * |
| | | * @param resources |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public void setDingding(MeetingRoomReservation resources) throws Exception { |
| | | // 获取存储用户钉钉号 |
| | | List<String> dingDingList = new ArrayList<>(); |
| | | public void sendNotice(MeetingRoomReservation resources) { |
| | | // 获取存储用户企微ID |
| | | List<String> weComList = new ArrayList<>(); |
| | | // 查询用户 |
| | | List<User> userList = userRepository.findAll(); |
| | | for(User user : userList){ |
| | | Role role = user.getRoles().iterator().next(); |
| | | // 获取项目组长级以上的用户的钉钉id |
| | | // 获取项目组长级以上的用户的企微ID |
| | | if(Long.valueOf(role.getLevel()) <= Constant.ROLE_LEVEL_LEADER){ |
| | | if(ObjectUtils.isNotEmpty(user.getDingding())){ |
| | | dingDingList.add(user.getDingding()); |
| | | if (StringUtils.isNotBlank(user.getWeComId())) { |
| | | weComList.add(user.getWeComId()); |
| | | } |
| | | } |
| | | } |
| | | // 查询会议室 |
| | | MeetingRoom meetingRoom = meetingRoomRepository.findById(resources.getMeetingId()).orElseGet(MeetingRoom::new); |
| | | // 发送内容至钉钉 |
| | | opaiDingTalkService.sendNotice(dingDingList, "会议室预约提示", "### 会议室预约提示 \n >" + |
| | | " \n 会议主题:" + resources.getMeetingTheme() + |
| | | " \n 预订者:" + SecurityUtils.getCurrentUsername() + |
| | | " \n 会议室:" + meetingRoom.getConferenceRoomName() + |
| | | " \n 开始时间: " + resources.getStartTime().toString().substring(0,19) + |
| | | " \n 结束时间: " + resources.getEndTime().toString().substring(0,19) + |
| | | " \n 会议室预约有变更,请登录PMS系统查看。", "card"); |
| | | // 发送内容至企微 |
| | | weComService.sendNotice(weComList, "会议室预约提示", String.format("<div class=\"normal\">会议主题:%s</div>" + |
| | | "<div class=\"normal\">预订者:%s</div>" + |
| | | "<div class=\"normal\">会议室:%s</div>" + |
| | | "<div class=\"normal\">开始时间:%s</div>" + |
| | | "<div class=\"normal\">结束时间:%s</div>" + |
| | | "<div class=\"highlight\">会议室预约有变更,请登录PMS系统查看。</div>", |
| | | resources.getMeetingTheme(), |
| | | SecurityUtils.getCurrentUsername(), |
| | | meetingRoom.getConferenceRoomName(), |
| | | resources.getStartTime().toString().substring(0, 19), |
| | | resources.getEndTime().toString().substring(0, 19)), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | } |
| | | |
| | | @Override |